Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Stats.cpp

Go to the documentation of this file.
00001 
00033 #include "viewpoints.h"
00034 #include "Stats.h"
00035 
00036 void STATINFO::InitStats()
00037 {
00038         bCompViewStats = false;
00039         
00040         queryObj.Clear();
00041         rightClass.Clear();
00042         wrongClass.Clear();
00043         neigType1.Clear();
00044         neigType2.Clear();
00045         topRanked.Clear();
00046 
00047         nParamsToSet = 6;
00048 }
00049 
00050 int STATINFO::FindDAGPos(int nDAGId) const
00051 {
00052         for (int i = 0; i < matchList.size(); i++)
00053                 if (matchList[i].nDAGId == nDAGId)
00054                         return i;
00055 
00056         return NOT_SET;
00057 }
00058  
00062 void STATINFO::ComputeStats(const DAG* pQueryDag)
00063 {
00064         int i, v, v1 = 0, v2 = 0, v3 = 0;
00065         const DAG* pModelDag;
00066 
00067         const int v0 = pQueryDag->GetViewNumber();
00068         ASSERT(v0 > 0);
00069 
00070         InitStats();
00071 
00072         GetClosestViews(v0, 3, v1, v2, v3);
00073 
00074         SmartArray<int> secLevClosViews(0, 9);
00075         GetClosestViews2(v0, 3, secLevClosViews, false);
00076 
00077         ASSERT(v1 != v0 && v2 != v0 && v3 != v0);
00078         ASSERT(v1 != v2 && v1 != v3 && v2 != v3);
00079         ASSERT(v1 > 0 && v2 > 0 && v3 > 0);
00080         ASSERT(v1 <= MAXVIEW && v2 <= MAXVIEW && v3 <= MAXVIEW);
00081 
00082         // For simplicity, we first find the position of the query DAG
00083         // so that we can account for the fact that it should not be ranked.
00084         queryObj.SetRankPos(FindDAGPos(pQueryDag->GetDAGId()), matchList);
00085 
00086         int nParamSet = 1; // query dag is already set
00087 
00088         // Now, look for the DAGs that will give the statistics we need.
00089         for (i = 0; i < matchList.size() && nParamSet < GetParamCount(); i++)
00090         {
00091                 pModelDag = matchList[i].ptrDAG;
00092 
00093                 if (matchList[i].dSimilarity == 0.0 || pModelDag == NULL)
00094                         continue;
00095 
00096                 if (topRanked.IsNotSet() && matchList[i].nDAGId != pQueryDag->GetDAGId())
00097                         topRanked.SetRankPos(i, matchList);
00098 
00099                 if (pQueryDag->GetObjName() == pModelDag->GetObjName())
00100                 {
00101                         v = pModelDag->GetViewNumber();
00102 
00103                         if (rightClass.IsNotSet() && v != v0)
00104                         {
00105                                 rightClass.SetRankPos(i, matchList, queryObj);
00106                                 nParamSet++;
00107                         }
00108 
00109                         if (neigType1.IsNotSet() && (v == v1 || v == v2 || v == v3))
00110                         {
00111                                 neigType1.SetRankPos(i, matchList, queryObj);
00112                                 nParamSet++;
00113 
00114                                 //set also the second degree neighbour
00115                                 if (neigType2.IsNotSet())
00116                                 {
00117                                         neigType2.SetRankPos(i, matchList, queryObj);
00118                                         nParamSet++;
00119                                 }
00120                         }
00121 
00122                         if (neigType2.IsNotSet())
00123                         {
00124                                 for (int n = 0; n < secLevClosViews.GetSize(); n++)
00125                                 {
00126                                         if (secLevClosViews[n] == v)
00127                                         {
00128                                                 neigType2.SetRankPos(i, matchList, queryObj);
00129                                                 nParamSet++;
00130                                                 break;
00131                                         }
00132                                 }
00133                         }
00134                 }
00135                 else if (wrongClass.IsNotSet()) {
00136                         wrongClass.SetRankPos(i, matchList, queryObj);
00137                         nParamSet++;
00138                 }
00139         }
00140 
00141         bCompViewStats = true;
00142 }
00143 
00149 void STATINFO::ComputeCrossRankingIdxStats(const STATINFO& matStats)
00150 {
00151         // For simplicity, we first find the position of the query DAG
00152         // so that we can account for the fact that it should not be ranked.
00153         queryObj.SetIdxPos(FindDAGPos(queryObj.GetDAGId()), matchList);
00154 
00155         int i, nDAGId, nParamSet = 1; // query dag is already set
00156 
00157         for (i = 0; i < matchList.size() && nParamSet < GetParamCount(); i++)
00158         {
00159                 nDAGId = matchList[i].nDAGId;
00160 
00161                 if (nDAGId == matStats.topRanked.GetDAGId()) {
00162                         topRanked.SetIdxPos(i, matchList, queryObj);
00163                         nParamSet++;
00164                 }
00165 
00166                 if (nDAGId == matStats.rightClass.GetDAGId()) {
00167                         rightClass.SetIdxPos(i, matchList, queryObj);
00168                         nParamSet++;
00169                 }
00170 
00171                 if (nDAGId == matStats.wrongClass.GetDAGId()) {
00172                         wrongClass.SetIdxPos(i, matchList, queryObj);
00173                         nParamSet++;
00174                 }
00175 
00176                 if (nDAGId == matStats.neigType1.GetDAGId()) {
00177                         neigType1.SetIdxPos(i, matchList, queryObj);
00178                         nParamSet++;
00179                 }
00180 
00181                 if (nDAGId == matStats.neigType2.GetDAGId()) {
00182                         neigType2.SetIdxPos(i, matchList, queryObj);
00183                         nParamSet++;
00184                 }
00185         }
00186 }
00187 
00188 void STATINFO::WriteHeader(ostream& os, int nFileIdx, int nIdxKBest, double dMaxOcclusionRate)
00189 {
00190         os <<
00191                 "\n% (1)idx (2)view# (3)comptime (4)occlusionRate "
00192                 "(5-10)idxRightClass (11-16)idxNeigType1 (17-22)idxNeigType2 "
00193                 "(23-28)idxWrongClass (29-34)idxTopRanked "
00194                 "(35-40)matRightClass (41-46)matNeigType1 (47-52)matNeigType2 "
00195                 "(53-58)matWrongClass (59-64)matTopRanked\n\n";
00196 
00197         os << "%kBest=" << nIdxKBest << ";\n";
00198         os << "%maxOcclusionRate=" << dMaxOcclusionRate << ";\n";
00199 
00200         os << "m" << nFileIdx << " = [";
00201 }
00202 
00203 void STATINFO::Write(ostream& os, int i, int nViewNum, const STATINFO& idxSt, const STATINFO& matSt,
00204         double dCompTime, double dOcclusionRate)
00205 {
00206         ASSERT(idxSt.bCompViewStats && matSt.bCompViewStats);
00207 
00208         os << endl << i << ' '
00209                 << nViewNum << ' '
00210                 << dCompTime << ' '
00211                 << dOcclusionRate << ' '
00212                 << idxSt << ' '
00213                 << matSt;
00214  }
00215 
00216 void STATINFO::WriteTailer(ostream& os)
00217 {
00218         os << "\n];\n" << flush;
00219         //os << "% plot(m(:,2), m(:,8), '.');\n" 
00220 }
00221 
00222 ostream& operator<<(ostream& os, const STATINFO& v)
00223 {
00224         return os << v.rightClass << ' ' << v.neigType1 << ' '
00225                 << v.neigType2 << ' ' << v.wrongClass << ' ' << v.topRanked;
00226 }
00227 
00229 //
00230 
00231 void STATINFO::INFOVAR::Clear()
00232 {
00233         nDAGId = NOT_SET;
00234         dSimilarity = NOT_SET;
00235         nBestRankingPosition = NOT_SET;
00236         nWorstRankingPosition = NOT_SET;
00237         nBestIdxPos = NOT_SET;
00238         nWorstIdxPos = NOT_SET;
00239 }
00240 
00241 ostream& operator<<(ostream& os, const STATINFO::INFOVAR& v)
00242 {
00243         return os << v.nDAGId << ' ' << v.dSimilarity << ' '
00244                 << v.nBestRankingPosition << ' ' << v.nWorstRankingPosition << ' '
00245                 << v.nBestIdxPos << ' ' << v.nWorstIdxPos;
00246 }
00247 
00252 void STATINFO::INFOVAR::SetRankPos(int currentRankPos, const leda_array<MatchInfo>& rankList)
00253 {
00254         if (currentRankPos != NOT_SET)
00255         {
00256                 nDAGId = rankList[currentRankPos].nDAGId;
00257                 dSimilarity = rankList[currentRankPos].dSimilarity;
00258                 nBestRankingPosition = GetBestPos(currentRankPos, rankList);
00259                 nWorstRankingPosition = GetWorstPos(currentRankPos, rankList);
00260         }
00261         else
00262         {
00263                 nDAGId = NOT_SET;
00264                 dSimilarity = NOT_SET;
00265                 nBestRankingPosition = NOT_SET;
00266                 nWorstRankingPosition = NOT_SET;
00267         }
00268 }
00269 
00274 void STATINFO::INFOVAR::SetRankPos(int currentRankPos,
00275         const leda_array<MatchInfo>& rankList, const STATINFO::INFOVAR& queryPos)
00276 {
00277         SetRankPos(currentRankPos, rankList);
00278 
00279         if (queryPos.nBestRankingPosition != NOT_SET &&
00280                 queryPos.nBestRankingPosition < nBestRankingPosition)
00281         {
00282                 nBestRankingPosition--;
00283                 nWorstRankingPosition--;
00284         }
00285 }
00286 
00291 void STATINFO::INFOVAR::SetIdxPos(int currentRankPos, const leda_array<MatchInfo>& rankList)
00292 {
00293         if (currentRankPos != NOT_SET)
00294         {
00295                 nBestIdxPos = GetBestPos(currentRankPos, rankList);
00296                 nWorstIdxPos = GetWorstPos(currentRankPos, rankList);
00297         }
00298         else
00299         {
00300                 nBestIdxPos = NOT_SET;
00301                 nWorstIdxPos = NOT_SET;
00302         }
00303 }
00304 
00309 void STATINFO::INFOVAR::SetIdxPos(int currentRankPos,
00310         const leda_array<MatchInfo>& rankList, const STATINFO::INFOVAR& queryPos)
00311 {
00312         SetIdxPos(currentRankPos, rankList);
00313 
00314         if (queryPos.nBestIdxPos != NOT_SET &&
00315                 queryPos.nBestIdxPos < nBestIdxPos)
00316         {
00317                 nBestIdxPos--;
00318                 nWorstIdxPos--;
00319         }
00320 }
00321 
00322 bool STATINFO::INFOVAR::IsNotSet() const
00323 {
00324         return nBestRankingPosition == NOT_SET;
00325 }
00326 
00333 int STATINFO::INFOVAR::GetBestPos(int i, const leda_array<MatchInfo>& matches)
00334 {
00335         double sim = matches[i].dSimilarity;
00336 
00337         while (i > 0 && matches[i - 1].dSimilarity == sim)
00338                 i--;
00339 
00340         return i;
00341 }
00342 
00349 int STATINFO::INFOVAR::GetWorstPos(int i, const leda_array<MatchInfo>& matches)
00350 {
00351         double sim = matches[i].dSimilarity;
00352 
00353         while (i < matches.size() - 1 && matches[i + 1].dSimilarity == sim)
00354                 i++;
00355 
00356         return i;
00357 }
00358 
00359 
00361 // Helper functions
00362 
00370 bool GetClosestViews(int i, int res, int& a, int& b, int& c)
00371 {
00372         //CViewPoints pts(128);
00373         COctahedronPoints pts(res);
00374 
00375         int* pNeigPts = pts.GetNeighbours(i - 1, 3);
00376 
00377         a = pNeigPts[0] + 1;
00378         b = pNeigPts[1] + 1;
00379         c = pNeigPts[2] + 1;
00380 
00381         free(pNeigPts);
00382 
00383         return true;
00384 }
00385 
00386 bool GetClosestViews2(int i, int res, SmartArray<int>& neigs, bool bIncludeFirstLevel)
00387 {
00388         int a[3], b[3];
00389         int j, k;
00390 
00391         GetClosestViews(i, res, a[0], a[1], a[2]);
00392 
00393         if (bIncludeFirstLevel)
00394                 for (j = 0; j < 3; j++)
00395                         neigs.AddTail(a[j]);
00396 
00397         for (j = 0; j < 3; j++)
00398         {
00399                 GetClosestViews(a[j], res, b[0], b[1], b[2]);
00400 
00401                 for (k = 0; k < 3; k++)
00402                         if (b[k] != i)
00403                                 neigs.AddTail(b[k]);
00404         }
00405 
00406         return true;
00407 }
00408 
00409 SmartArray<int> Complement128(int tgt, const int* views, int n)
00410 {
00411         int viewmap[128], i, j;
00412         SmartArray<int> comp(128 - n - 1);
00413 
00414         memset(viewmap, 0, 128 * sizeof(int));
00415         viewmap[tgt - 1] = 1;
00416 
00417         for (i = 0; i < n; i++)
00418         {
00419                 ASSERT(viewmap[views[i]] == 0);
00420                 viewmap[views[i]] = 1;
00421         }
00422 
00423         for (i = 0, j = 0; i < 128; i++)
00424                 if (viewmap[i] == 0)
00425                         comp[j++] = i;
00426 
00427         ASSERT(j == comp.GetSize());
00428 
00429         return comp;
00430 }
00431 
00432 
00433 
00434 int CompInt(const void *elem1, const void *elem2 )
00435 {
00436         return int(elem1) - int(elem2);
00437 }
00438 
00439 SmartArray<int> GetFarthestViews(int i, int res, double deg)
00440 {
00441         SmartArray<int> h1, h2, h, views;
00442 
00443         h1 = GetClosestViewsByRange(i, 3, 90);
00444         h2 = Complement128(i, h1, h1.GetSize());
00445 
00446         h2.Sort(CompInt);
00447         DBG_VAL(h2.GetSize());
00448         h2.Print();
00449         cout << endl << endl;
00450 
00451         for (int i = 0; i < h2.GetSize(); i++)
00452         {
00453                 h = GetClosestViewsByRange(h2[i] + 1, 3, 90);
00454                 h.AddTail(h2[i]);
00455                 h.Sort(CompInt);
00456                 cout << endl << h2[i] << endl;
00457                 h.Print();
00458 
00459                 if (h == h2)
00460                 {
00461                         DBG_MSG("GOT IT")
00462                         views.AddTail(h2[i]);
00463                 }
00464         }
00465         DBG_VAL(views.GetSize());
00466         return views;
00467 }
00468 
00469 SmartArray<int> GetClosestViewsByRange(int i, int res, const double& range)
00470 {
00471         COctahedronPoints pts(res);
00472         int n = 63;
00473 
00474         int* pNeigPts = pts.GetNeighbours(i - 1, range, n);
00475         //int* pNeigPts = pts.GetNeighbours(i - 1, n);
00476         SmartArray<int> views(n);
00477 
00478         for (int j = 0; j < n; j++)
00479                 views.AddTail(pNeigPts[j]);
00480 
00481         free(pNeigPts);
00482 
00483         return views;
00484 }
00485 
00486 SmartArray<int> GetSymmetricViewMap()
00487 {
00488         const int nViewsPerObj = 128, nClosestNeig = 127;
00489         COctahedronPoints pts(3);
00490         SmartArray<int> symmap(nViewsPerObj + 1); // view 0 isn't used
00491         int* pNeigPts;
00492 
00493         for (int i = 1; i <= nViewsPerObj; i++)
00494         {
00495                 pNeigPts = pts.GetNeighbours(i - 1, nClosestNeig);
00496                 symmap[i] = pNeigPts[nClosestNeig - 1] + 1;
00497                 free(pNeigPts);
00498         }
00499 
00500         return symmap;
00501 }
00502 
00503 /*SmartArray<int> GetSymmetricViewMap()
00504 {
00505         const int nViewsPerObj = 128;
00506         SmartArray<int> symmap, views;
00507         int viewmap[nViewsPerObj], i, j, k;
00508 
00509         symmap.ReSize(nViewsPerObj + 1, true); // view 0 isn't used
00510 
00511         for (i = 1; i <= nViewsPerObj; i++)
00512         {
00513                 views = GetClosestViewsByRange(i, 3, 182); // 178 = a bit less than 180.
00514 
00515                 // Turn off all views
00516                 memset(viewmap, 0, nViewsPerObj * sizeof(int));
00517 
00518                 // Turn on views that are within 178 deg.
00519                 for (j = 0; j < views.GetSize(); j++)
00520                         viewmap[views[j] - 1] = 1;
00521 
00522                 // Turn on the target view
00523                 viewmap[i - 1] = 1;
00524 
00525                 // There should be only one view off = 0
00526                 for (k = 0; k < nViewsPerObj; k++)
00527                         if (viewmap[k] == 0 && symmap[i] == 0)
00528                                 symmap[i] = k + 1;
00529                         else if (viewmap[k] == 0 && symmap[i] != 0)
00530                         {
00531                                 ShowError("Multiple symmetric views.");
00532                                 ASSERT(false);
00533                         }
00534                         else if (k == nViewsPerObj - 1 && symmap[i] == 0 && viewmap[k] != 0)
00535                         {
00536                                 ShowError("One view is unmapped.");
00537                                 ASSERT(false);
00538                         }
00539         }
00540 
00541         return symmap;
00542 }*/
00543 

Generated on Sat Nov 13 11:21:26 2004 for Noisy DAG Matcher by doxygen1.2.18