void CArcView::computeEnclosingRect(BOOL init) { CRect unionRect; Point currentPoint(*pathPoints.begin()); for(auto it=pathPoints.begin() + 1; it != pathPoints.end(); ++it) { //Union des rectangles. CRect toAddRect(currentPoint.X, currentPoint.Y, it->X, it->Y); toAddRect.NormalizeRect(); if(toAddRect.Width() == 0) toAddRect.InflateRect(1,0); if(toAddRect.Height() == 0) toAddRect.InflateRect(0,1); unionRect.UnionRect(unionRect, toAddRect); currentPoint = *it; } if(init) enclosingRect = new Rect(unionRect.left, unionRect.top, unionRect.Width(), unionRect.Height()); else { enclosingRect->X = unionRect.left; enclosingRect->Y = unionRect.top; enclosingRect->Width = unionRect.Width(); enclosingRect->Height = unionRect.Height(); } }
void CDuiScrollBar::OnMouseMove(UINT nFlags, CPoint point) { if(m_bDrag) { int nInterHei=(IsVertical()?m_rcWindow.Height():m_rcWindow.Width())-2*m_uAllowSize; int nSlideHei=m_si.nPage*nInterHei/(m_si.nMax-m_si.nMin+1); if(nSlideHei<THUMB_MINSIZE) nSlideHei=THUMB_MINSIZE; if(nInterHei<THUMB_MINSIZE) nSlideHei=0; int nEmptyHei=nInterHei-nSlideHei; int nDragLen=IsVertical()?(point.y-m_ptDrag.y):(point.x-m_ptDrag.x); int nSlide=(nEmptyHei==0)?0:(nDragLen*(int)(m_si.nMax-m_si.nMin-m_si.nPage+1)/nEmptyHei); int nNewTrackPos=m_nDragPos+nSlide; if(nNewTrackPos<m_si.nMin) { nNewTrackPos=m_si.nMin; } else if(nNewTrackPos>(int)(m_si.nMax-m_si.nMin-m_si.nPage+1)) { nNewTrackPos=m_si.nMax-m_si.nMin-m_si.nPage+1; } if(nNewTrackPos!=m_si.nTrackPos) { CRect rcOldThumb=GetPartRect(SB_THUMBTRACK); m_si.nTrackPos=nNewTrackPos; CRect rcThumb=GetPartRect(SB_THUMBTRACK); CRect rcUnion; rcUnion.UnionRect(rcOldThumb,rcThumb); HDC hdc=GetDuiDC(&rcUnion,OLEDC_PAINTBKGND); m_pSkin->Draw(hdc,rcUnion,MAKESBSTATE(SB_PAGEUP,SBST_NORMAL,m_bVertical),m_byAlpha); m_pSkin->Draw(hdc,rcThumb,MAKESBSTATE(SB_THUMBTRACK,SBST_HOVER,m_bVertical),m_byAlpha); ReleaseDuiDC(hdc); NotifySbCode(SB_THUMBTRACK,m_si.nTrackPos); } } else { UINT uHit=HitTest(point); if(uHit!=m_uHtPrev) { if(m_uHtPrev!=-1) { CRect rc=GetPartRect(m_uHtPrev); HDC hdc=GetDuiDC(&rc,OLEDC_PAINTBKGND); m_pSkin->Draw(hdc,rc,MAKESBSTATE(m_uHtPrev,SBST_NORMAL,m_bVertical),m_byAlpha); ReleaseDuiDC(hdc); } if(uHit!=-1) { CRect rc=GetPartRect(uHit); HDC hdc=GetDuiDC(&rc,OLEDC_PAINTBKGND); m_pSkin->Draw(hdc,rc,MAKESBSTATE(uHit,SBST_HOVER,m_bVertical),m_byAlpha); ReleaseDuiDC(hdc); } m_uHtPrev=uHit; } } }
void CLogo::SetPosition() { if(!::IsWindow(m_hWnd)) return; CDockBar* pTopDockBar = GetParentDockBar(); if(!pTopDockBar) return; CRect TopDockBarRect; pTopDockBar->GetClientRect(TopDockBarRect); CRect LogoRect; GetWindowRect(LogoRect); pTopDockBar->ScreenToClient(LogoRect); int nLeft = TopDockBarRect.right-LogoRect.Width()-::GetSystemMetrics(SM_CXEDGE); int nTop = TopDockBarRect.top; if(nLeft != LogoRect.left || nTop != LogoRect.top) SetWindowPos(NULL, nLeft, nTop, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE); CRect UnionToolbarRect; for(int nI=0;nI<pTopDockBar->m_arrBars.GetSize();nI++) { CWnd* pWnd = static_cast<CWnd*>(pTopDockBar->m_arrBars[nI]); if(!pWnd || !AfxIsValidAddress(pWnd,sizeof(CWnd)) || !::IsWindow(*pWnd)) continue; CRect ToolBarRect; pWnd->GetWindowRect(&ToolBarRect); UnionToolbarRect.UnionRect(UnionToolbarRect,ToolBarRect); } GetWindowRect(LogoRect); UnionToolbarRect.IntersectRect(UnionToolbarRect,LogoRect); if(UnionToolbarRect.IsRectEmpty()) { if(!IsWindowVisible()) ShowWindow(SW_SHOW); } else { if(IsWindowVisible()) ShowWindow(SW_HIDE); } }
void CBCGPAppointmentDSMap::Add (const COleDateTime& date, const CRect& rect) { CBCGPAppointmentDrawStruct* pDS = NULL; BOOL bEmpty = IsEmpty (); if (!bEmpty) { pDS = Get (date); } if (pDS == NULL) { if (!bEmpty) { XDateInterval& interval = m_DSMap[m_DSMap.GetSize () - 1]; CBCGPAppointmentDrawStruct* pDSPrev = interval.m_pDS; if (IsConcatenate () && interval.m_date2 < date && (date - interval.m_date2).GetTotalDays () <= 1.0) { if (pDSPrev->GetRect ().top == rect.top && pDSPrev->GetRect ().bottom == rect.bottom) { CRect rt; rt.UnionRect (pDSPrev->GetRect (), rect); pDSPrev->SetRect (rt); pDSPrev->SetBorder((CBCGPAppointmentDrawStruct::BCGP_APPOINTMENT_DS_BORDER) (pDSPrev->GetBorder () | CBCGPAppointmentDrawStruct::BCGP_APPOINTMENT_DS_BORDER_FINISH)); interval.m_date2 = date; return; } } pDSPrev->SetBorder ((CBCGPAppointmentDrawStruct::BCGP_APPOINTMENT_DS_BORDER) (pDSPrev->GetBorder () & ~CBCGPAppointmentDrawStruct::BCGP_APPOINTMENT_DS_BORDER_FINISH)); pDS = CreateStruct (); pDS->SetBorder (CBCGPAppointmentDrawStruct::BCGP_APPOINTMENT_DS_BORDER_FINISH); } else { pDS = CreateStruct (); pDS->SetBorder (CBCGPAppointmentDrawStruct::BCGP_APPOINTMENT_DS_BORDER_START); } XDateInterval interval(date, pDS); m_DSMap.Add(interval); } pDS->SetRect (rect); }
BOOL CXTPDockingPaneSplitterWnd::GetAvailableRect(CRect& rcAvail, CRect& rcUnion) { CXTPDockingPaneManager* pManager = GetDockingPaneManager(); if (!pManager) return FALSE; int nSplitterSize = pManager->GetPaintManager()->m_nSplitterSize; BOOL bHoriz = m_pContainer->m_bHoriz; ASSERT(m_pFirst && m_pSecond); if (!m_pFirst || !m_pSecond) return FALSE; CRect rcFirst = m_pFirst->GetPaneWindowRect(); CRect rcSecond = m_pSecond->GetPaneWindowRect(); MINMAXINFO mmiFirst, mmiSecond; m_pFirst->GetMinMaxInfo(&mmiFirst); m_pSecond->GetMinMaxInfo(&mmiSecond); rcAvail.UnionRect(rcFirst, rcSecond); rcUnion = rcAvail; int nGap = pManager->m_nSplitterGap; if (bHoriz) { rcAvail.DeflateRect(max(mmiFirst.ptMinTrackSize.x, nGap), 0, max(mmiSecond.ptMinTrackSize.x + nSplitterSize, nGap), 0); if (rcUnion.Width() > mmiFirst.ptMaxTrackSize.x) rcAvail.right = min(rcAvail.right, rcUnion.left + mmiFirst.ptMaxTrackSize.x); if (rcUnion.Width() > mmiSecond.ptMaxTrackSize.x) rcAvail.left = max(rcAvail.left, rcUnion.right - mmiSecond.ptMaxTrackSize.x - nSplitterSize); if (rcAvail.left >= rcAvail.right) return FALSE; } else { rcAvail.DeflateRect(0, max(mmiFirst.ptMinTrackSize.y, nGap), 0, max(mmiSecond.ptMinTrackSize.y + nSplitterSize, nGap)); if (rcUnion.Height() > mmiFirst.ptMaxTrackSize.y) rcAvail.bottom = min(rcAvail.bottom, rcUnion.top + mmiFirst.ptMaxTrackSize.y); if (rcUnion.Height() > mmiSecond.ptMaxTrackSize.y) rcAvail.top = max(rcAvail.top, rcUnion.bottom - mmiSecond.ptMaxTrackSize.y - nSplitterSize); if (rcAvail.top >= rcAvail.bottom) return FALSE; } return TRUE; }
CRect CStandardNodePositioning::BoundingRect (const CStandardLayoutNodeInfo* node) { // walk along this branch CRect result = node->rect; for ( ; node != NULL; node = node->nextInBranch) { result.UnionRect (result, node->rect); // shift sub-branches for ( CStandardLayoutNodeInfo* branch = node->firstSubBranch ; branch != NULL ; branch = branch->nextBranch) { result.UnionRect (result, BoundingRect (branch)); } } return result; }
void shape_mgr::get_rect(CRect &rect) { rect.SetRect(0, 0, 0 ,0); if (shapes_.size() == 0) return; shapes_[0]->get_rect(rect); for (int i=1; i<shapes_.size(); i++) { CRect rc; shapes_[i]->get_rect(rc); rect.UnionRect(&rect, &rc); } }
int CDuiScrollBar::SetPos(int nPos) { if(nPos>(m_si.nMax-(int)m_si.nPage+1)) nPos=(m_si.nMax-m_si.nPage+1); if(nPos<m_si.nMin) nPos=m_si.nMin; if(nPos!=m_si.nPos) { if(m_si.nTrackPos==-1) { CRect rcOldThumb=GetPartRect(SB_THUMBTRACK); m_si.nTrackPos=nPos; CRect rcNewThumb=GetPartRect(SB_THUMBTRACK); CRect rcUnion; rcUnion.UnionRect(&rcOldThumb,&rcNewThumb); HDC hdc=GetDuiDC(&rcUnion,OLEDC_PAINTBKGND); m_pSkin->Draw(hdc,rcUnion,MAKESBSTATE(SB_PAGEDOWN,SBST_NORMAL,IsVertical())); m_pSkin->Draw(hdc,rcNewThumb,MAKESBSTATE(SB_THUMBTRACK,SBST_NORMAL,IsVertical())); ReleaseDuiDC(hdc); m_si.nTrackPos=-1; } m_si.nPos=nPos; } return m_si.nPos; }
CRect CRevisionGraphWnd::GetViewRect() { CRect result; result.UnionRect (GetClientRect(), GetGraphRect()); return result; }
void CShArray::MoveShape(CShape *pSh,LPRECT lpRecLast,BOOL bReconnect /*=TRUE*/){ //Move shape in array CRect rectInter; if(1){ //Rectangles does not overlap. //if(pSh->m_Rect.IntersectRect(pSh->m_Rect,lpRecLast)){ int origen_x=CRect(lpRecLast).TopLeft().x/m_szCell.cx; int origen_y=CRect(lpRecLast).TopLeft().y/m_szCell.cy; int limit_x=CRect(lpRecLast).BottomRight().x/m_szCell.cx; int limit_y=CRect(lpRecLast).BottomRight().y/m_szCell.cy; int j; for(j=origen_y;j<=limit_y;j++){ for(int i=origen_x;i<=limit_x;i++){ POSITION pos=m_vvRows[j][i].Find(pSh); if(pos){ m_vvRows[j][i].RemoveAt(pos); int nCount=m_vvRows[j][i].GetCount(); } }} origen_x=pSh->m_Rect.TopLeft().x/m_szCell.cx; origen_y=pSh->m_Rect.TopLeft().y/m_szCell.cy; limit_x=pSh->m_Rect.BottomRight().x/m_szCell.cx; limit_y=pSh->m_Rect.BottomRight().y/m_szCell.cy; for(j=origen_y;j<=limit_y;j++){ for(int i=origen_x;i<=limit_x;i++){ m_vvRows[j][i].AddTail(pSh); }} } //Rectangles overlap else{ CRect rectUnion; rectUnion.UnionRect(pSh->m_Rect,lpRecLast); CRect rectUpper,rectLower; if(pSh->m_Rect.TopLeft().y>CRect(lpRecLast).TopLeft().y){ } else{ } if(pSh->m_Rect.TopLeft().y>CRect(lpRecLast).TopLeft().y){ int origen_x=CRect(lpRecLast).TopLeft().x/m_szCell.cx; int origen_y=CRect(lpRecLast).TopLeft().y/m_szCell.cy; int limit_x=CRect(lpRecLast).TopLeft().x/m_szCell.cx; int limit_y=rectInter.TopLeft().y/m_szCell.cy; for(int j=origen_y;j<=limit_y;j++){ for(int i=origen_x;i<=limit_x;i++){ m_vvRows[j][i].AddTail(pSh); }} } else{ } } //Try to reconnect shapes //#define DCABLE_SHARRAY_RECONNECT #ifdef DCABLE_SHARRAY_RECONNECT if(bReconnect){ if(pSh->IsKindOf(RUNTIME_CLASS(CShapeUnit))){ CShapeUnit *pShUnit=(CShapeUnit *)pSh; //1.Prepare a map of points pointer to lists of objects. std::map<CPoint,CObject*> map; std::map<CPoint,int> map_index; //2. Iterate pins in shape for(int i=0;i<pShUnit->m_obarrShapearr.GetSize();i++){ CShape *pSh=(CShape *)pShUnit->m_obarrShapearr[i]; if(pSh->IsKindOf(RUNTIME_CLASS(CShapePin))){ CShapePin *pShPin=(CShapePin *)pSh; CPoint pt=pShPin->m_rectPin.CenterPoint()+pShPin->m_Rect.TopLeft(); pt=CPoint(pt.x/m_szCell.cx,pt.y/m_szCell.cy); std::map<CPoint,CObject*>::iterator it=map.find( pt); if(it==map.end()){ CList<CObject*,CObject*> *cells=new CList<CObject*,CObject*>; map[pt]=cells; map_index[pt]=i; it=map.find(pt); } CList<CObject*,CObject*> *cells=(CList<CObject*,CObject*> *)it->second; if(!cells->Find(pShPin)){ cells->AddTail(pShPin); } } } //3. Try to connect pins for(std::map<CPoint,CObject*>::iterator it=map.begin();it!=map.end();++it){ CList<CObject*,CObject*> *cells=(CList<CObject*,CObject*> *)it->second; for(POSITION q=cells->GetHeadPosition();cells->GetNext(q);q!=cells->GetTailPosition( )){ int i=it->first.x; int j=it->first.y; for(POSITION p=m_vvRows[i][j].GetHeadPosition();m_vvRows[i][j].GetNext(p);p!=m_vvRows[i][j].GetTailPosition( )){ if(pSh->IsKindOf(RUNTIME_CLASS(CShapeWire))){ CShape *pShconn=NULL; CShape *pShchild=NULL; CShapePin *pShPin=(CShapePin *)cells->GetAt(q); //check temp conection CPoint pt_conn=pShPin->m_rectPin.CenterPoint()+pShPin->GetParent()->m_Rect.TopLeft(); //19/01/2005: new connecting mechanism BOOL bConnectionTmp=FALSE;//set when a connection is pending CShapeContainer *pShContConnect=NULL; bConnectionTmp=((CShapeContainer*)pSh)->PtInRect(&pt_conn,&pShContConnect); //Previous mechanism to 19/01/2005 is commented /* int mode_prev=pSh->m_Mode; pSh->OnLButtonDown(0,pt_conn); pSh->m_Mode=mode_prev; */ //19/01/2005: new connecting mechanism if(bConnectionTmp){ CShapeContainer *pShCont1=(CShapeContainer *)pShUnit; CShape *pSh=(*pShCont1)[0]; if(pSh->IsKindOf(RUNTIME_CLASS(CShapeContainer))){ CShapeContainer *pShCont2=(CShapeContainer *)pSh; pShCont1->LinkShapes(pShContConnect,pShCont2); } } //Previous mechanism to 19/01/2005 is commented /* //After lbutton click detination container contains information about destination pin if(pSh->m_pshChildConn){ pShconn=pSh;//pointer to destination container pShchild=pSh->m_pshChildConn;//pointer to pin of destination container } //Connect if(pShconn){ //To connect put in source container information about destination pin (container,pin) //Call SetConnection(...) passing source index. pShUnit->m_pshConn=pShconn; pShUnit->m_pshChildConn=pShchild; int nIndex=map_index[it->first]; pShchild=pShUnit->SetConnection(NULL,nIndex); //Call SetConnection(...) for destination container. //Destination container matches pin using destination->m_pshChildConn that was unaltered //since lbutton click. //Destination put information in pin using supplied parameters. pShconn->m_pshConn=pShUnit; pShconn->SetConnection(pShchild); } */ } } } } //4.Clean up of map for(it=map.begin();it!=map.end();++it){ delete(it->second); } }//end of if is kind of CShapeUnit }//end of flag reconnect #endif }
void CConfigDisplay::setupSample() { UpdateData(TRUE); m2v(); copy2lf(m_samplelfTitles,m_samplelfPanel,m_samplelfColHdr/*,m_samplelfCurPlay*/); static int first = 1; if (first) { first = 0; m_SamplePlaylist.initFont(); } COLORREF crTransMain,crTransPanel; MBCONFIG_READ_TRANS_COLORS(m_regSD,crTransMain,crTransPanel); // Column Header m_FontSampleColHdr.DeleteObject(); m_FontSampleColHdr.CreateFontIndirect(&m_samplelfColHdr); m_SampleColHdr.SetFont(&m_FontSampleColHdr, TRUE); m_SampleColHdr.changeFont(&m_FontSampleColHdr); m_SampleColHdr.setText("Artists"); m_SampleColHdr.SetColors(m_vTxColHdr, m_vBkColHdr, m_vcrColHdrInUL,m_vcrColHdrInLR,m_vcrColHdrOutUL,m_vcrColHdrOutLR, m_3dColHdr); CRect rectColHdr; m_SampleColHdr.GetWindowRect(rectColHdr); ScreenToClient(rectColHdr); // Data Window CRect rectData,rectDataNew; m_SamplePlaylist.GetWindowRect(rectData); ScreenToClient(rectData); rectDataNew = rectColHdr; rectDataNew.top = rectColHdr.bottom; rectDataNew.bottom = rectDataNew.top + rectData.Height(); rectDataNew.right = (rectDataNew.left + rectColHdr.Width()); CDC * cdc = GetDC(); LPLOGFONT lplf = &m_samplelfTitles; m_SamplePlaylist.changeFont(lplf); // Status CRect rectStatus,rectStatusNew; m_SamplePanel.GetWindowRect(rectStatus); ScreenToClient(rectStatus); rectStatusNew = rectColHdr; rectStatusNew.top = rectDataNew.bottom+5; rectStatusNew.bottom = rectStatusNew.top + rectStatus.Height(); m_FontSamplePanel.DeleteObject(); m_FontSamplePanel.CreateFontIndirect(&m_samplelfPanel); m_SamplePanel.SetFont(&m_FontSamplePanel, TRUE); m_SamplePanel.changeFont(&m_FontSamplePanel); m_SamplePanel.setText("01:30/03:29 Howling Fish by Big Fish Howlers"); m_SamplePanel.SetTicking(TRUE); m_SamplePanel.SetColors(m_vTxPanel,m_vBkPanel,\ m_vcrStatusInUL,m_vcrStatusInLR,m_vcrStatusOutUL,m_vcrStatusOutLR,\ m_3dStatus); m_SamplePanel.MoveWindow(rectStatusNew); m_SamplePlaylist.ResetContent(); m_SamplePlaylist.AddString(" all"); m_SamplePlaylist.AddString("Little Twisty Big Fun Band"); m_SamplePlaylist.AddString("Twisty Little Big Fun Band"); m_SamplePlaylist.AddString("Big Fun Little Twisty Band"); m_SamplePlaylist.AddString("Fun Big Little Twisty Band"); m_SamplePlaylist.AddString("Band O Little Twisty Big Fun Folks"); m_SamplePlaylist.AddString("Little Twisty Big Fun Band O Folks"); m_SamplePlaylist.AddString("Twisty Fun Big Band O Littles"); m_SamplePlaylist.AddString("Xyzzy"); m_SamplePlaylist.AddString("Big Little Band O Little Twisties"); m_SamplePlaylist.AddString("Plugh"); m_SamplePlaylist.AddString("Did you get the memo about the new cover sheets for our TPS Reports?"); m_SamplePlaylist.AddString("There is an Easter Egg on the about screen."); m_SamplePlaylist.MoveWindow(rectDataNew); m_SamplePlaylist.SetBitmaps(cdc, getSkin(MB_SKIN_SCROLLUPARROW),crTransPanel, getSkin(MB_SKIN_SCROLLDOWNARROW),crTransPanel, getSkin(MB_SKIN_SCROLLBUTTON),crTransPanel, getSkin(MB_SKIN_SCROLLBACKGROUND),crTransPanel); m_SamplePlaylist.SetColors(m_vBkNormal,m_vBkHigh,m_vBkSel, m_vTxNormal,m_vTxHigh,m_vTxSel,m_3dData, m_vcrDataInUL,m_vcrDataInLR,m_vcrDataOutUL,m_vcrDataOutLR); ReleaseDC(cdc); CDIBSectionLite bmp; if (!bmp.Load(getSkin(MB_SKIN_BACKGROUNDLIBRARY))) { m_SampleColHdr.RedrawWindow(); m_SamplePanel.RedrawWindow(); m_SamplePlaylist.invalidate(); m_SamplePlaylist.RedrawWindow(); return; } CRect grect; grect.UnionRect(rectColHdr,rectStatusNew); grect.InflateRect(10,10,10,10); CDC * dc = GetDC(); LayOutStyle BackgroundMainType,BackgroundPanelType; MBCONFIG_READ_BACKGROUND_TYPES(m_regSD,BackgroundMainType,BackgroundPanelType); BitmapToCRect bmcr((HBITMAP)bmp, grect, BackgroundPanelType, bmp.GetWidth(), bmp.GetHeight()); // dc->FillSolidRect(grect, RGB(0,255,0)); MBUtil::BmpToDC(dc, &bmcr, TRUE, crTransPanel, 0); ReleaseDC(dc); m_SampleColHdr.RedrawWindow(); m_SamplePanel.RedrawWindow(); m_SamplePlaylist.invalidate(); m_SamplePlaylist.RedrawWindow(); }
void CModuleWnd::GetDragInfoData(LPSTGMEDIUM lpStgMedium) { ASSERT_VALID(this); ASSERT(AfxIsValidAddress(lpStgMedium, sizeof(STGMEDIUM))); int nItem; CModuleDoc::CModule* pModule; CRect rcBound; rcBound.SetRectEmpty(); CClientDC dc(this); dc.BeginPath(); POSITION pos = GetListCtrl()->GetFirstSelectedItemPosition(); while (pos) { nItem = GetListCtrl()->GetNextSelectedItem(pos); pModule = m_pCurrentDocument->GetModule(nItem); CRect rcObj = pModule->m_rcPosition.GetRECT(); rcObj.NormalizeRect(); rcBound.UnionRect(rcBound, rcObj); dc.MoveTo(rcObj.left, rcObj.top); dc.LineTo(rcObj.right, rcObj.top); dc.LineTo(rcObj.right, rcObj.bottom); dc.LineTo(rcObj.left, rcObj.bottom); dc.LineTo(rcObj.left, rcObj.top); } dc.EndPath(); CPoint ptStart = rcBound.CenterPoint(); theApp.AlignToGrid(ptStart); LPSTREAM lpStream; if (::CreateStreamOnHGlobal(NULL, TRUE, &lpStream) != S_OK) AfxThrowMemoryException(); ASSERT(lpStream != NULL); lpStream->Write(&rcBound, sizeof(CRect), NULL); lpStream->Write(&ptStart, sizeof(CPoint), NULL); int iNumPoints = dc.GetPath(NULL, NULL, 0); CPoint* pPoints = new CPoint[iNumPoints]; if (pPoints == NULL) AfxThrowMemoryException(); BYTE* pTypes = new BYTE[iNumPoints]; if (pTypes == NULL) AfxThrowMemoryException(); iNumPoints = dc.GetPath(pPoints, pTypes, iNumPoints); lpStream->Write(&iNumPoints, sizeof(int), NULL); lpStream->Write(pPoints, sizeof(CPoint) * iNumPoints, NULL); lpStream->Write(pTypes, sizeof(BYTE) * iNumPoints, NULL); if (pPoints != NULL) delete pPoints; if (pTypes != NULL) delete pTypes; // setup the STGMEDIUM lpStgMedium->tymed = TYMED_ISTREAM; lpStgMedium->pstm = lpStream; lpStgMedium->pUnkForRelease = NULL; }
//coverage the minimum intersection requirement, gap the maximum distance between pixels //to become a candidate matched edge pixel void ChangeDetector::MorphDiff(float coverage, float gap){ int i,j,k,amount=refList1.size(); CvMat Ma, Mb; int x0,y0,h0,w0,mx,my,mh,mw; int pos,dest,total,cand,bl,nbl; CRect meg; //compute distance of boundaries in segmentation 1 to that of segmentation 2 for(i=0;i<amount;++i){ if((float)refList1[i].section/regList1[i].size<coverage){ continue; } cand=refList1[i].bestp; meg.UnionRect(®List1[i].boundBox, ®List2[cand].boundBox); h0=meg.Height(); w0=meg.Width(); BYTE*patch=new BYTE[h0*w0]; float *pool=new float[h0*w0]; memset(patch,1,sizeof(BYTE)*h0*w0); cvInitMatHeader( &Ma, h0, w0, CV_8UC1, patch); cvInitMatHeader( &Mb, h0, w0, CV_32FC1, pool); x0=meg.left; y0=meg.top; mx=regList2[cand].boundBox.left; my=regList2[cand].boundBox.top; mw=regList2[cand].boundBox.Width(); mh=regList2[cand].boundBox.Height(); pos=my*width+mx; total=0;//number of pixel in a region // bl=0;//boundary length for(j=0;j<mh;++j) { for(k=0;k<mw;++k) { if(tag2[pos]==cand) { if(CheckNei(tag2,width,height,pos)!=4){ // ++bl; dest=(j+my-y0)*w0+(k+mx-x0); patch[dest]=0; } ++total; } ++pos; } pos+=width-mw; } assert(total==regList2[cand].size); cvDistTransform(&Ma,&Mb,CV_DIST_L2,3); //sum up the pixels of distance less than gap mx=regList1[i].boundBox.left; my=regList1[i].boundBox.top; mw=regList1[i].boundBox.Width(); mh=regList1[i].boundBox.Height(); pos=my*width+mx; total=0; bl=0; nbl=0;//matched boundry length for(j=0;j<mh;++j) { for(k=0;k<mw;++k) { if(tag1[pos]==i) { if(CheckNei(tag1,width,height,pos)!=4){ ++bl; dest=(j+my-y0)*w0+(k+mx-x0); nbl+=pool[dest]<=gap?1:0; } ++total; } ++pos; } pos+=width-mw; } assert(nbl<=bl); refList1[i].gDist=(float)nbl/bl; assert(total==regList1[i].size); delete[]patch; delete[]pool; } amount=refList2.size(); //compute distance of boundaries in segmentation 2 to that of segmentation 1 for(i=0;i<amount;++i){ if((float)refList2[i].section/regList2[i].size<coverage) continue; cand=refList2[i].bestp; meg.UnionRect(®List2[i].boundBox, ®List1[cand].boundBox); h0=meg.Height(); w0=meg.Width(); BYTE*patch=new BYTE[h0*w0]; float *pool=new float[h0*w0]; memset(patch,1,sizeof(BYTE)*h0*w0); cvInitMatHeader( &Ma, h0, w0, CV_8UC1, patch); cvInitMatHeader( &Mb, h0, w0, CV_32FC1, pool); x0=meg.left; y0=meg.top; mx=regList1[cand].boundBox.left; my=regList1[cand].boundBox.top; mw=regList1[cand].boundBox.Width(); mh=regList1[cand].boundBox.Height(); pos=my*width+mx; total=0;//number of pixel in a region // bl=0;//boundary length for(j=0;j<mh;++j) { for(k=0;k<mw;++k) { if(tag1[pos]==cand) { if(CheckNei(tag1,width,height,pos)!=4){ // ++bl; dest=(j+my-y0)*w0+(k+mx-x0); patch[dest]=0; } ++total; } ++pos; } pos+=width-mw; } assert(total==regList1[cand].size); cvDistTransform(&Ma,&Mb,CV_DIST_L2,3); //sum up the pixels of distance less than gap mx=regList2[i].boundBox.left; my=regList2[i].boundBox.top; mw=regList2[i].boundBox.Width(); mh=regList2[i].boundBox.Height(); pos=my*width+mx; total=0; bl=0; nbl=0;//matched boundry length for(j=0;j<mh;++j) { for(k=0;k<mw;++k) { if(tag2[pos]==i) { if(CheckNei(tag2,width,height,pos)!=4){ ++bl; dest=(j+my-y0)*w0+(k+mx-x0); nbl+=pool[dest]<=gap?1:0; } ++total; } ++pos; } pos+=width-mw; } assert(nbl<=bl); refList2[i].gDist=(float)nbl/bl; assert(total==regList2[i].size); delete[]patch; delete[]pool; } }