void CPropertiesWnd::OnPropDownitem() { if (!IsComboType()) { return; } CMFCPropertyGridProperty *pProp = m_wndPropList.GetCurSel(); if (pProp && pProp->IsGroup()) { CString strName(pProp->GetName()); if (strName.CompareNoCase(_T("ITEM")) == 0) { CMFCPropertyGridProperty *pParentProp = pProp->GetParent(); if (pProp == pParentProp->GetSubItem(pParentProp->GetSubItemsCount() - 1)) { return; } int nEnd = 0; CList<CMFCPropertyGridProperty*, CMFCPropertyGridProperty*> lstSubItems; for (int i = pParentProp->GetSubItemsCount() - 1; i >= nEnd; i--) { CMFCPropertyGridProperty *pChildProp = pParentProp->GetSubItem(i); if (pChildProp) { if (pChildProp == pProp) { nEnd = i; lstSubItems.InsertAfter(lstSubItems.GetHeadPosition(), pChildProp); } else { lstSubItems.AddHead(pChildProp); } pParentProp->RemoveSubItem(pChildProp, FALSE); } } for (POSITION pos = lstSubItems.GetHeadPosition(); pos != NULL;) { CMFCPropertyGridProperty* pProp = lstSubItems.GetNext(pos); ASSERT_VALID(pProp); pParentProp->AddSubItem(pProp); } m_wndPropList.AdjustLayout(); } } }
CLibraryFolder* CLibraryFolderCtrl::GetNextSelectedFolder(POSITION& pos) const { CLibraryFolder* pFolder = NULL; do { if ( pos == NULL ) return NULL; HTREEITEM hItem = (HTREEITEM)pos; pos = (POSITION)GetNextSelectedItem( hItem ); if ( hItem == m_hRoot ) continue; CList< HTREEITEM > pTree; while ( hItem != m_hRoot ) { pTree.AddHead( hItem ); hItem = GetParentItem( hItem ); } CLibraryFolder* pLastFolder = NULL; for ( POSITION posTree = pTree.GetHeadPosition() ; posTree ; pLastFolder = pFolder ) { hItem = pTree.GetNext( posTree ); pFolder = (CLibraryFolder*)GetItemData( hItem ); if ( pLastFolder ) { if ( pLastFolder->CheckFolder( pFolder ) ) continue; } else { if ( LibraryFolders.CheckFolder( pFolder ) ) continue; } pFolder = NULL; break; } } while ( pFolder == NULL ); return pFolder; }
void CPlayerPlaylistBar::OnLvnKeyDown(NMHDR* pNMHDR, LRESULT* pResult) { LPNMLVKEYDOWN pLVKeyDown = reinterpret_cast<LPNMLVKEYDOWN>(pNMHDR); *pResult = FALSE; CList<int> items; POSITION pos = m_list.GetFirstSelectedItemPosition(); while (pos) { items.AddHead(m_list.GetNextSelectedItem(pos)); } if (pLVKeyDown->wVKey == VK_DELETE && items.GetCount() > 0) { pos = items.GetHeadPosition(); while (pos) { int i = items.GetNext(pos); if (m_pl.RemoveAt(FindPos(i))) { ((CMainFrame*)AfxGetMainWnd())->CloseMedia(); } m_list.DeleteItem(i); } m_list.SetItemState(-1, 0, LVIS_SELECTED); m_list.SetItemState( max(min(items.GetTail(), m_list.GetItemCount() - 1), 0), LVIS_SELECTED, LVIS_SELECTED); ResizeListColumn(); *pResult = TRUE; } else if (pLVKeyDown->wVKey == VK_SPACE && items.GetCount() == 1) { m_pl.SetPos(FindPos(items.GetHead())); ((CMainFrame*)AfxGetMainWnd())->OpenCurPlaylistItem(); AfxGetMainWnd()->SetFocus(); *pResult = TRUE; } }
/** * 响应鼠标单击按钮;Reverse * @param CBCGPGridCtrl* pGridCtrlEdit 输入行 * @param CBCGPGridCtrl* pGridCtrlList 列表 * @param CList<int, int>* plsNb Nb号队列指针 * @return void */ void CGridCtrlOperation::OnBnClickedButtonReverseA(CBCGPGridCtrl* pGridCtrlEdit, CBCGPGridCtrl* pGridCtrlList) { CList<int, int> ListNb; CList<int, int>* plsNb = &ListNb; // 得到索引队列,修改操作、删除操作、颠倒操作 if(false == GetIndexListForChangeOrDeleteOrReverse(pGridCtrlEdit, pGridCtrlList, plsNb)) { return; } CBCGPGridRow* pRow = NULL; // 行 CBCGPGridRow* pRowMax = NULL; // 排序行 CBCGPGridRow* pRowNew = NULL; // 新行 CList<int, int> olsNb; int iNbStart = -1; int iNbEnd = -1; int iRowIndex = -1; int i, j; POSITION posMax; POSITION pos; int iNbMax; int iNb; // 得到Nb队列 for(i = 0; i < plsNb->GetCount(); i++) { pos = plsNb->FindIndex(i); iRowIndex = plsNb->GetAt(pos); iNb = pGridCtrlList->GetRow(iRowIndex)->GetData(); olsNb.AddTail(iNb); if(0 == i) { iNbStart = iNb; } if((plsNb->GetCount() - 1) == i) { iNbEnd = iNb; } } // 对Nb排序,由小到大 for(i = 0; i < olsNb.GetCount(); i++) { posMax = olsNb.FindIndex(i); iNbMax = olsNb.GetAt(posMax); for(j = i + 1; j < olsNb.GetCount(); j++) { pos = olsNb.FindIndex(j); iNb = olsNb.GetAt(pos); if(iNbStart < iNbEnd) { if(iNbMax > iNb) { iNbMax = iNb; posMax = pos; } } else { if(iNbMax < iNb) { iNbMax = iNb; posMax = pos; } } } olsNb.RemoveAt(posMax); olsNb.AddHead(iNbMax); } for(i = 0; i < plsNb->GetCount(); i++) { pos = plsNb->FindIndex(i); iRowIndex = plsNb->GetAt(pos); pRow = pGridCtrlList->GetRow(iRowIndex); posMax = olsNb.FindIndex(i); iNbMax = olsNb.GetAt(posMax); pRowMax = pGridCtrlList->FindRowByData(iNbMax); pRowNew = pGridCtrlList->CreateRow(pGridCtrlList->GetColumnCount()); pGridCtrlList->AddRow(pRowNew, FALSE); pRowNew->SetData(pRow->GetData()); pRowNew->GetItem(0)->SetValue(pRow->GetItem(0)->GetValue()); for(int j = 1; j < pGridCtrlList->GetColumnCount(); j++) { COleVariant oVariant = pRow->GetItem(j)->GetValue(); pRowNew->GetItem(j)->SetValue(oVariant); } pRow->SetData(pRowMax->GetData()); pRow->GetItem(0)->SetValue(pRowMax->GetItem(0)->GetValue()); for(int j = 1; j < pGridCtrlList->GetColumnCount(); j++) { COleVariant oVariant = pRowMax->GetItem(j)->GetValue(); pRow->GetItem(j)->SetValue(oVariant); } pRowMax->SetData(pRowNew->GetData()); pRowMax->GetItem(0)->SetValue(pRowNew->GetItem(0)->GetValue()); for(int j = 1; j < pGridCtrlList->GetColumnCount(); j++) { COleVariant oVariant = pRowNew->GetItem(j)->GetValue(); pRowMax->GetItem(j)->SetValue(oVariant); } pGridCtrlList->RemoveRow((pGridCtrlList->GetRowCount() - 1), FALSE); } pGridCtrlList->AdjustLayout(); }
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; }
//********************************************************************************* int CBCGPVisualManagerVS2005::CreateAutoHideButtonRegion (CRect rect, DWORD dwAlignment, LPPOINT& points) { switch (dwAlignment & CBRS_ALIGN_ANY) { case CBRS_ALIGN_LEFT: rect.right--; break; case CBRS_ALIGN_TOP: rect.bottom--; break; } CRect rectOrign = rect; DWORD dwAlignmentOrign = dwAlignment; if ((dwAlignment & CBRS_ALIGN_ANY) == CBRS_ALIGN_LEFT || (dwAlignment & CBRS_ALIGN_ANY) == CBRS_ALIGN_RIGHT) { rect = CRect (0, 0, rectOrign.Height (), rectOrign.Width ()); dwAlignment = (dwAlignment == CBRS_ALIGN_LEFT) ? CBRS_ALIGN_TOP : CBRS_ALIGN_BOTTOM; } CList<POINT, POINT> pts; if (!m_bRoundedAutohideButtons) { rect.right--; pts.AddHead (CPoint (rect.left, rect.top)); pts.AddHead (CPoint (rect.left, rect.bottom - 2)); pts.AddHead (CPoint (rect.left + 2, rect.bottom)); pts.AddHead (CPoint (rect.right - 2, rect.bottom)); pts.AddHead (CPoint (rect.right, rect.bottom - 2)); pts.AddHead (CPoint (rect.right, rect.top)); } else { POSITION posLeft = pts.AddHead (CPoint (rect.left, rect.top)); posLeft = pts.InsertAfter (posLeft, CPoint (rect.left, rect.top + 2)); POSITION posRight = pts.AddTail (CPoint (rect.right, rect.top)); posRight = pts.InsertBefore (posRight, CPoint (rect.right, rect.top + 2)); int xLeft = rect.left + 1; int xRight = rect.right - 1; int y = 0; BOOL bIsHorz = (dwAlignmentOrign & CBRS_ALIGN_ANY) == CBRS_ALIGN_LEFT || (dwAlignmentOrign & CBRS_ALIGN_ANY) == CBRS_ALIGN_RIGHT; for (y = rect.top + 2; y < rect.bottom - 4; y += 2) { posLeft = pts.InsertAfter (posLeft, CPoint (xLeft, y)); posLeft = pts.InsertAfter (posLeft, CPoint (xLeft, y + 2)); posRight = pts.InsertBefore (posRight, CPoint (xRight, y)); posRight = pts.InsertBefore (posRight, CPoint (xRight, y + 2)); xLeft++; xRight--; } if ((dwAlignmentOrign & CBRS_ALIGN_ANY) == CBRS_ALIGN_BOTTOM && !bIsHorz) { xLeft--; xRight++; } if (bIsHorz) { xRight++; } for (;y < rect.bottom - 1; y++) { posLeft = pts.InsertAfter (posLeft, CPoint (xLeft, y)); posLeft = pts.InsertAfter (posLeft, CPoint (xLeft + 1, y + 1)); posRight = pts.InsertBefore (posRight, CPoint (xRight, y)); posRight = pts.InsertBefore (posRight, CPoint (xRight - 1, y + 1)); if (y == rect.bottom - 2) { posLeft = pts.InsertAfter (posLeft, CPoint (xLeft + 1, y + 1)); posLeft = pts.InsertAfter (posLeft, CPoint (xLeft + 3, y + 1)); posRight = pts.InsertBefore (posRight, CPoint (xRight, y + 1)); posRight = pts.InsertBefore (posRight, CPoint (xRight - 2, y + 1)); } xLeft++; xRight--; } posLeft = pts.InsertAfter (posLeft, CPoint (xLeft + 2, rect.bottom)); posRight = pts.InsertBefore (posRight, CPoint (xRight - 2, rect.bottom)); } points = new POINT [pts.GetCount ()]; int i = 0; for (POSITION pos = pts.GetHeadPosition (); pos != NULL; i++) { points [i] = pts.GetNext (pos); switch (dwAlignmentOrign & CBRS_ALIGN_ANY) { case CBRS_ALIGN_BOTTOM: points [i].y = rect.bottom - (points [i].y - rect.top); break; case CBRS_ALIGN_RIGHT: { int x = rectOrign.right - points [i].y; int y = rectOrign.top + points [i].x; points [i] = CPoint (x, y); } break; case CBRS_ALIGN_LEFT: { int x = rectOrign.left + points [i].y; int y = rectOrign.top + points [i].x; points [i] = CPoint (x, y); } break; } } return (int) pts.GetCount (); }