/****************************************************************************** Function Name : vIDCopy Input(s) : omDestMap, omSrcMap of IDs Output : - Functionality : Copies the source ID map values into destination. Member of : CMessageAttrib Author(s) : Arunkumar K Date Created : 08-03-2011 Modifications : ******************************************************************************/ void CMessageAttrib::vIDCopy(CList <UINT, UINT&>& omDestMap, CList <UINT, UINT&>& omSrcMap) { UINT unMsgID; omDestMap.RemoveAll(); POSITION psCurrPos = omSrcMap.GetHeadPosition(); while (psCurrPos != NULL) { unMsgID = omSrcMap.GetNext(psCurrPos); omDestMap.AddTail(unMsgID); } }
void mpc_filehash(CPlaylist& pl, CList<filehash>& fhs) { fhs.RemoveAll(); POSITION pos = pl.GetHeadPosition(); while (pos) { CString fn = pl.GetNext(pos).m_fns.GetHead(); if (AfxGetAppSettings().m_Formats.FindExt(CPath(fn).GetExtension().MakeLower(), true)) { continue; } filehash fh; if (!mpc_filehash(fn, fh)) { continue; } fhs.AddTail(fh); } }
void CPopulation::AssignRankAndCrowdingDistance() { ASSERT(individuals != NULL); ASSERT(pProblem != NULL); int front_size = 0; int rank = 1; int orig_index, cur_index; POSITION pos1, pos2, tmp_pos; CList<int, int> orig; CList<int, int> cur; for (int i=0; i<pProblem->popsize; i++) orig.AddTail(i); while (!orig.IsEmpty()) { pos1 = orig.GetHeadPosition(); orig_index = orig.GetNext(pos1); if (pos1 == NULL) { individuals[orig_index].rank = rank; individuals[orig_index].crowd_dist = INF; break; } cur.AddHead(orig_index); front_size = 1; orig.RemoveHead(); pos1 = orig.GetHeadPosition(); while (pos1 != NULL) { int flag = -1; orig_index = orig.GetAt(pos1); pos2 = cur.GetHeadPosition(); while (pos2 != NULL) { cur_index = cur.GetAt(pos2); flag = individuals[orig_index].CheckDominance(individuals[cur_index]); if (flag == 1) { orig.AddHead(cur_index); front_size--; tmp_pos = pos2; cur.GetNext(pos2); cur.RemoveAt(tmp_pos); } else if (flag == 0) { cur.GetNext(pos2); } else if (flag == -1) { break; } } if (flag != -1) { cur.AddHead(orig_index); front_size++; tmp_pos = pos1; orig.GetNext(pos1); orig.RemoveAt(tmp_pos); } else { orig.GetNext(pos1); } } pos2 = cur.GetHeadPosition(); while (pos2 != NULL) { cur_index = cur.GetNext(pos2); individuals[cur_index].rank = rank; } AssignCrowdingDistanceList((void*) &cur, front_size); cur.RemoveAll(); rank++; } }
// -------------------------------------------------------------------------- int GroupingEventDetector::DetectEvents(int nFrame, CNewVisionDoc* doc) { /* The fitness of body Bi in group Gj can be determined as f(Bi, Gj) = W_dwell * f_dwell + W_alignment * f_alignment + W_cohesion * f_cohesion Where f_* are functions that compute ( Co-dwelling: dwell near the same or nearby fixture as swarm-mates Alignment: align towards the average heading of the local swarm-mates Cohesion: position itself close to the average position of local swarm-mates ) and W_* are respective weights f_dwell(Bi, Gj) = || Bi_dwell_fixture_xy && mean(Gj_dwell_fixture_xy) || f_alignment(Bi, Gj) = (Bi_velocity, mean(Gj_velocity)) f_cohesion(Bi, Gj) = 1 / || Bi_xy, mean(Gj_xy) || */ if (nFrame % m_everyNframe) return -1; // --------- At each frame perfom a mapping of Bi (bodies) to Gi (groups)------------ // Create a temporary queue of recent events CList<SwarmEvent*, SwarmEvent*> recentEvents; SmartPtrArray<BodyCluster> cl; SmartPtrArray<BodyCluster> cl_copy; BodyCluster all; for (POSITION pos = doc->m_TrackingData.data.GetStartPosition();pos;) { int id; BodyPath *bp; doc->m_TrackingData.data.GetNextAssoc(pos, id, bp); if (nFrame < bp->startFrame || nFrame > bp->startFrame+bp->GetUpperBound()) continue; Step s = bp->GetAt(nFrame-bp->startFrame); if (!s.visible) continue; bool dwell = bp->ComputeDwellingState(nFrame, doc->bodyactivitymodel.m_pathSmoothSigma, doc->bodyactivitymodel.m_dwellTime, doc->bodyactivitymodel.m_dwellAreaRadius); double orientation = bp->GetMotionAngle(nFrame, doc->bodyactivitymodel.m_pathSmoothSigma); BodyClusterElement *bce = new BodyClusterElement(id, cvPoint3D32f(s.p.x, s.p.y, 0), s.orientation, dwell); cl.Add(new BodyCluster(bce)); all.Add(bce); } // (1.0) Prepare a set of N singleton clusters and NxN distance matrix int N = cl.GetCount(); if (N < 2) return 0; CvMat* D = cvCreateMat(N, N, CV_64FC1); // lower-left diagonal matrix cvSet(D, cvScalar(FLT_MAX)); for (int i = 0;i < N;i++) for (int j = 0;j < i;j++) { double d = ComputeDistance(cl[i], cl[j]); cvSetReal2D(D, i, j, d); cvSetReal2D(D, j, i, d); } CvMat* D_elements = (CvMat*)cvClone(D); // (2.0) Perform agglomerative clustering double kValidityNow = ComputeGroupClusteringValidity(doc, cl, &all, D_elements); // to determine the optimal number of clusters compute clustering validity index double kValidityBefore = 0; int step=0; String ^msg = gcnew String(""); do { double min_val, max_val; CvPoint min_loc, max_loc; cl_copy.Copy(cl); cvMinMaxLoc(D, &min_val, &max_val, &min_loc, &max_loc); if (min_val == FLT_MAX) break; BodyCluster *b1 = cl[min_loc.x], *b2= cl[min_loc.y]; // break if no more close bodies if (d(b1->bot, b2->bot) > m_maxGroupDiameter ) break; // merge //doc->Message(String::Concat("Add ", b2->id, " at [", b2->bot.x, ", ", b2->bot.y, "] to ", b1->id, " at [", b1->bot.x, ", ", b1->bot.y, "]")); b1->Add(b2); //doc->Message(String::Concat("Result at [", b1->bot.x, ", ", b1->bot.y, "] ")); b2->sub.RemoveAllPointers(); // change row and col 'min_loc.x' for (int i=0;i<N;i++) { if (i == min_loc.x) continue; double dist = ComputeDistance(cl[i], b1); cvSetReal2D(D, i, min_loc.x, dist); cvSetReal2D(D, min_loc.x, i, dist); } // erase row and col 'min_loc.y' for (int i=0;i<N;i++) { cvSetReal2D(D, i, min_loc.y, FLT_MAX); cvSetReal2D(D, min_loc.y, i, FLT_MAX); } msg += String::Format("{0:f2}:{1:f2} ", isolation, compactness); kValidityBefore = kValidityNow; kValidityNow = ComputeGroupClusteringValidity(doc, cl, &all, D_elements); step++; } while (kValidityNow > kValidityBefore); msg += String::Format("{0:f2}:{1:f2} ", isolation, compactness); //doc->Message(msg); //doc->Message(String::Format("step={3:d1} {0:f2}+{1:f2}={2:f2} ", isolation, compactness, kValidityNow, step)); // (3.0) populate group events array int EVENT_FRAME_CONFIDENCE = 100; double MAX_EVENT_DISTANCE_TO_MERGE = 0.01; // if some actors are different the distance will usually be > 0.02 int count = cl_copy.GetCount(); for (int i=0;i<count;i++) { if (cl_copy[i]->sub.GetCount() < 2) continue; SwarmEvent* ev1 = new SwarmEvent(nFrame, name); for (int k=0;k<cl_copy[i]->sub.GetCount();k++) ev1->AddActor(cl_copy[i]->sub[k]->id, kValidityNow); //// Update a temporary queue of recent events: find the closest existing event with all actors matching, then merge //double maxDistance = FLT_MAX; int eid = -1; //SwarmEvent* ev2 = NULL, *evMatch = NULL; //for (POSITION posE = recentEvents.GetHeadPosition();posE;) //{ // ev2 = recentEvents.GetNext(posE); // // do not merge if too far apart in time (treat as separate events) // if (ev1->GetAverageFrameDistance(ev2) > EVENT_FRAME_CONFIDENCE) // break; // double d = ev1->DistanceSQR(ev2); // if (d < maxDistance ) { // ev2 is the closest to ev1 // maxDistance = d; // evMatch = ev2; // } // //echo(String::Format("dist {0}",ev1->GetAverageFrameDistance(ev2))); //} //// if found an almost identical event match - merge //if (evMatch && maxDistance < MAX_EVENT_DISTANCE_TO_MERGE) { // ev2->Add(ev1); // SwarmEvent::last_id--; //} //// otherwise, create a new event map entry //else recentEvents.AddHead(ev1); } // (4.0) Move events from temporary queue to the events map for (POSITION posE = recentEvents.GetHeadPosition();posE;) { SwarmEvent *ev = recentEvents.GetNext(posE); doc->m_ActivityData.sEvent.SetAt(ev->id, ev); } // (5.0) Cleanup cvReleaseMat(&D); cvReleaseMat(&D_elements); recentEvents.RemoveAll(); cl.RemoveAll(); cl_copy.RemoveAll(); return count; }
void CHello2Dlg::OnProcessSel(int id) { int curch = m_chlist.GetCurSel(); if(m_cmdbase == ID_32773) //data operation { CList<double,double> *data = &m_ridlgs[curch]->m_data; if(m_ridlgs[curch]->show_type == SHOW_ORGDATA) data = &m_ridlgs[curch]->m_output; if(id == 1) //show converted result { m_ridlgs[curch]->show_type = SHOW_MAINDATA; } if(id == 2) //show raw result { m_ridlgs[curch]->show_type = SHOW_ORGDATA; } if(id == 3) //delete the current record { int pos = m_history.GetCurSel(); if((pos >= 0) && (data)) { POSITION p = data->GetHeadPosition(); while(pos-- > 0 ) data->GetNext(p); data->RemoveAt(p); } } if(id == 4) //delete all the record { data->RemoveAll(); } if(id == 5) //export all the record { CFile cf; if(!cf.Open(DATAOUT_NAME,CFile::modeCreate|CFile::modeWrite)) return; //write to txt and open with notepad if(data && (data->GetCount() > 0)) { POSITION pos = data->GetHeadPosition(); char r[50]; do{ double v = data->GetAt(pos); sprintf(r,"%8f\r\n",v); cf.Write(r,strlen(r)); if(pos == data->GetTailPosition()) break; data->GetNext(pos); }while(1); } cf.Close(); SHELLEXECUTEINFO execInf; ZeroMemory (&execInf, sizeof (execInf)); execInf.cbSize = sizeof (SHELLEXECUTEINFO); execInf.fMask = SEE_MASK_NOCLOSEPROCESS; execInf.nShow = SW_SHOWNORMAL; execInf.lpFile = _T("\\windows\\pword.exe"); execInf.lpVerb = _T("open"); execInf.lpParameters = DATAOUT_NAME; ShellExecuteEx (&execInf); } } if(m_cmdbase == ID_32772) { if(id == 1) { m_ridlgs[curview]->sidedata = NULL; }else{ m_ridlgs[curview]->sidedata = &m_ridlgs[id-2]->m_data; m_ridlgs[curview]->side_ch = id-2; } m_ridlgs[curview]->SaveLastConfig(); } if(m_cmdbase == ID_32771) //channel config { if(m_cfgtype == CFGTYPE_BORE) { CSetting<PROBECFG> prbset; prbset.InstallFromFile(PRB_DEFINFO); if(id == 1)//just close it { m_ridlgs[curch]->cfg_now = CFGTYPE_NONE; for(int i=0;i<sizeof(m_ridlgs)/sizeof(CRunitemDialog*);i++){ if((m_ridlgs[i]->cfg_now == CFGTYPE_BORE) && (i != curch) && (m_ridlgs[i]->side_ch == curch)) { m_ridlgs[i]->sidedata = NULL; } } }else{ m_ridlgs[curch]->m_prbid = prbset.GetNameAt(id-2); m_ridlgs[curch]->cfg_now = CFGTYPE_BORE; } m_ridlgs[curch]->SaveLastConfig(); } if(m_cfgtype == CFGTYPE_THMO) { if(m_ridlgs[curch]->IsValid() && (id == 1)) //just close it { m_ridlgs[curch]->cfg_now = CFGTYPE_NONE; for(int i=0;i<sizeof(m_ridlgs)/sizeof(CRunitemDialog*);i++){ if((m_ridlgs[i]->cfg_now == CFGTYPE_THMO) && (i != curch) && (m_ridlgs[i]->side_ch == curch)) { m_ridlgs[i]->sidedata = NULL; } } }else{ if(id != 1){ m_ridlgs[curch]->cfg_now = CFGTYPE_THMO; CString types(_T("TBEJKNRS")); m_ridlgs[curch]->m_prbid = types.GetAt(id-2); } } m_ridlgs[curch]->SaveLastConfig(); } } LoadCurrentView(); }
int CScreenPannel::SetShowPlayWin(int nMain, int nSub) { if (nSub < 0 || nSub > 16) { nSub = 0; } int nNum = 16; int nBegin = 0; switch(nMain) { case SCREEN_1MODE: nNum = 1; nBegin = nSub; break; case SCREEN_4MODE: nNum = 4; if (nSub >= 12) { nBegin = 12; } else if (nSub >= 8) { nBegin = 8; } else if (nSub >= 4) { nBegin = 4; } else { nBegin = 0; } break; case SCREEN_9MODE: nNum = 9; if (nSub >= 10) { nBegin = 7; } else { nBegin = 0; } break; case SCREEN_16MODE: nNum = 16; nBegin = 0; break; default: break; } CList<CWnd*, CWnd*> templist; POSITION pos = m_PageList.GetHeadPosition(); while(pos != NULL) { CWnd* pWnd = m_PageList.GetNext(pos); if (pWnd) { templist.AddTail(pWnd); } } m_PageList.RemoveAll(); /* while(m_PageList.GetCount()) { DelPage(GetTailPage()); } */ for(int i=nBegin; i < (nBegin+nNum); i++) { AddPage(&m_wndVideo[i], TRUE); } SetActivePage(&m_wndVideo[nSub], TRUE); pos = templist.GetHeadPosition(); while(pos != NULL) { CWnd* pWnd = templist.GetNext(pos); if (pWnd) { pWnd->ShowWindow(SW_HIDE); } } templist.RemoveAll(); return m_PageList.GetCount(); /* if (m_PageList.GetCount() > nNum) { int nCnt = m_PageList.GetCount(); while (nCnt > nNum) { CWnd* pWnd = DelPage(GetTailPage()); if (!pWnd) { DelPage(GetTailPage()); } nCnt = m_PageList.GetCount(); } //UpdateWnd(); SetActivePage(&m_wndVideo[0], TRUE); } else if (m_PageList.GetCount() < nNum) { int nCnt = m_PageList.GetCount(); while (nCnt < nNum) { AddPage(&m_wndVideo[nCnt], FALSE); nCnt = m_PageList.GetCount(); } //UpdateWnd(); SetActivePage(&m_wndVideo[0], TRUE); } return m_PageList.GetCount(); */ }