📄 printpatview.cpp
字号:
PelsSamp.Green = PixTemp.Green;
PelsSamp.Red = PixTemp.Red;
if(m_patTypeSel == shade) //底纹蓝色
{
MyPatternShade.AddTail(PelsSamp);
List.Format("%3d,%5d,%5d,%5d,%5d,%5d",MyPatternPrint.GetCount(),
PelsSamp.Coordinate.x,PelsSamp.Coordinate.y,PelsSamp.Red,PelsSamp.Green,PelsSamp.Blue);
m_pattenListBox.InsertString(ListIndex,List);
ListIndex++;
dc.SelectObject(&newbrush3);
pointSamp.x = PelsSamp.Blue+420;
pointSamp.y = 266-PelsSamp.Green;
dc.Ellipse(pointSamp.x-2,pointSamp.y-2,pointSamp.x+2,pointSamp.y+2);
}
if(m_patTypeSel == sign) //签字绿色
{
MyPatternSign.AddTail(PelsSamp);
List.Format("%3d,%5d,%5d,%5d,%5d,%5d",MyPatternSign.GetCount(),
PelsSamp.Coordinate.x,PelsSamp.Coordinate.y,PelsSamp.Red,PelsSamp.Green,PelsSamp.Blue);
m_pattenListBox.InsertString(ListIndex,List);
ListIndex++;
dc.SelectObject(&newbrush2);
pointSamp.x = PelsSamp.Blue+420;
pointSamp.y = 266-PelsSamp.Green;
dc.Ellipse(pointSamp.x-2,pointSamp.y-2,pointSamp.x+2,pointSamp.y+2);
}
}
}
}
if((m_RecMode == manual)&&(m_NumKinds==2)&&m_isSampleFinish)
{
CRect m_drawLineRect(420,6,800,266);
CClientDC dc(this);
CPen m_pen;
m_pen.CreatePen(PS_SOLID,1,RGB(0,0,0));
dc.SelectObject(&m_pen);
POINT tempPoint;
if(m_drawLineRect.PtInRect(point))
{
if(m_drawLinePointsList.GetCount() ==1)
{
tempPoint.x = point.x-420;
tempPoint.y = 266 - point.y;
m_drawLinePointsList.AddTail(tempPoint);
m_lineEnd = point;
dc.MoveTo(m_lineStart);
dc.LineTo(m_lineEnd);
}
if(m_drawLinePointsList.IsEmpty())
{
tempPoint.x = point.x -420;
tempPoint.y = 266-point.y;
m_drawLinePointsList.AddTail(tempPoint);
m_lineStart = point;
}
}
}
CFormView::OnLButtonDown(nFlags, point);
}
void CPrintPatView::OnUpdaeUIXIndicator(CCmdUI *pCmdUI)
{
CString str;
if(m_indicator_X == 2000)
{
str.Empty();
pCmdUI->SetText("X= ");
}
else
{
str.Format("X=%3d",m_indicator_X);
pCmdUI->SetText(str);
}
}
void CPrintPatView::OnUpdaeUIYIndicator(CCmdUI *pCmdUI)
{
CString str;
if(m_indicator_Y == 2000)
{
str.Empty();
pCmdUI->SetText("Y= ");
}
else
{
str.Format("Y=%3d",m_indicator_Y);
pCmdUI->SetText(str);
}
}
void CPrintPatView::OnUpdaeUIRIndicator(CCmdUI *pCmdUI)
{
CString str;
if(m_indicator_R == 2000)
{
str.Empty();
pCmdUI->SetText("R= ");
}
else
{
str.Format("R=%3d",m_indicator_R);
pCmdUI->SetText(str);
}
}
void CPrintPatView::OnUpdaeUIGIndicator(CCmdUI *pCmdUI)
{
CString str;
if(m_indicator_G == 2000)
{
str.Empty();
pCmdUI->SetText("G= ");
}
else
{
str.Format("G=%3d",m_indicator_G);
pCmdUI->SetText(str);
}
}
void CPrintPatView::OnUpdaeUIBIndicator(CCmdUI *pCmdUI)
{
CString str;
if(m_indicator_B == 2000)
{
str.Empty();
pCmdUI->SetText("B= ");
}
else
{
str.Format("B=%3d",m_indicator_B);
pCmdUI->SetText(str);
}
}
void CPrintPatView::OnUpdaeUICurrentColorIndicator(CCmdUI *pCmdUI)
{
((CMainFrame*)GetParent())->SetCurrentColor(RGB(m_indicator_R,m_indicator_G,m_indicator_B));
}
void CPrintPatView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
static Pix24Bitmap PixTemp;
CDib *m_pDib;
CClientDC m_lineDC(this);
CPen m_linePen;
m_linePen.CreatePen(PS_SOLID,1,RGB(0,0,0));
m_lineDC.SelectObject(&m_linePen);
m_pDib = GetDocument()->GetDibPoint();
CRect rect(20,30,20+m_nWidth,30+m_nHeight);
CRect LineRect(420,6,800,266);
if(rect.PtInRect(point)) //在状态栏显示下吧
{
PixTemp = m_pDib->LoadBitmapIndex(point.y-30,point.x-20);
m_indicator_X = point.x-20;
m_indicator_Y = point.y-30;
m_indicator_R = PixTemp.Red;
m_indicator_G = PixTemp.Green;
m_indicator_B = PixTemp.Blue;
}
else
{
m_indicator_X=m_indicator_Y=m_indicator_R=m_indicator_G=m_indicator_B=2000;
}
if((m_RecMode == manual)&&m_isSampleFinish&&LineRect.PtInRect(point))//手动,采样完成,可以划线
{
if(m_drawLinePointsList.GetCount() == 1)
{
DrawReferenceFrame();
DrawSampledPoints();
m_lineDC.MoveTo(m_lineStart);
m_lineDC.LineTo(point);
}
}
CFormView::OnMouseMove(nFlags, point);
}
void CPrintPatView::OnIsSampleFinishCheck()
{
// TODO: Add your control notification handler code here
m_isSampleFinish = m_isSampleFinishCheck.GetCheck();
if(m_isSampleFinish)
{
AfxMessageBox("可以分类了,手动就划线吧",MB_OK,0);
m_drawLinePointsList.RemoveAll();
}
}
void CPrintPatView::DrawReferenceFrame(void)
{
CClientDC dc(this); // device context for painting
CPen newpenSolid,*oldpen;
CBrush newbrush(RGB(255,0,0)),*oldbrush;
newpenSolid.CreatePen(PS_SOLID,1,RGB(0,0,0));
oldpen=dc.SelectObject(&newpenSolid);
dc.Rectangle(420,6,800,266);//原点是(420,266);
for(int i=520;i<800;i=i+100)
{
dc.MoveTo(i,266);
dc.LineTo(i,6);
}
for(int j=196;j>6;j=j-70)
{
dc.MoveTo(420,j);
dc.LineTo(800,j);
}
oldbrush=dc.SelectObject(&newbrush);
CString str1="0";
dc.TextOut(417,266,str1);
str1="100";
dc.TextOut(517,266,str1);
str1="200";
dc.TextOut(617,266,str1);
str1="300";
dc.TextOut(717,266,str1);
str1="70";
dc.TextOut(404,190,str1);
str1="140";
dc.TextOut(396,120,str1);
str1="210";
dc.TextOut(396,50,str1);
switch(m_TwoKindMode) {
case rANDb:
str1="R";
dc.TextOut(790,266,str1);
str1="X2:";
dc.TextOut(769,266,str1);
str1="B";
dc.TextOut(408,6,str1);
str1="X1:";
dc.TextOut(387,6,str1);
break;
case rANDg:
str1="R";
dc.TextOut(790,266,str1);
str1="X2:";
dc.TextOut(769,266,str1);
str1="G";
dc.TextOut(408,6,str1);
str1="X1:";
dc.TextOut(387,6,str1);
break;
case bANDg:
str1="G";
dc.TextOut(790,266,str1);
str1="X2:";
dc.TextOut(769,266,str1);
str1="B";
dc.TextOut(408,6,str1);
str1="X1:";
dc.TextOut(387,6,str1);
break;
default:
break;
}
// dc.Ellipse(438,244,442,248);//440,246
dc.SelectObject(oldpen);
newpenSolid.DeleteObject();
dc.SelectObject(oldbrush);
newbrush.DeleteObject();
}
void CPrintPatView::DrawSampledPoints(void)
{
Pels tempPels;
int index = 0;
POSITION pos;
POINT pointSample;
CClientDC dc(this);
CPen newPen,*oldPen;
newPen.CreatePen(PS_SOLID,1,RGB(0,0,0));
oldPen = dc.SelectObject(&newPen);
CBrush newBrush1(RGB(255,0,0)),newBrush2(RGB(0,255,0)),newBrush3(RGB(0,0,255)),*oldBrush;
oldBrush = dc.SelectObject(&newBrush1);
if(m_NumKinds == 2)
{
switch(m_TwoKindMode)
{
case rANDg:
if(!MyPatternPrint.IsEmpty())
{
dc.SelectObject(&newBrush1);
pos = MyPatternPrint.GetHeadPosition();
for(index = 0;index<MyPatternPrint.GetCount();index++)
{
tempPels = MyPatternPrint.GetNext(pos);
pointSample.x = tempPels.Red + 420;
pointSample.y = 266 - tempPels.Green;
dc.Ellipse(pointSample.x-2,pointSample.y-2,pointSample.x+2,pointSample.y+2);
}
}
if(!MyPatternSign.IsEmpty())
{
dc.SelectObject(&newBrush2);
pos = MyPatternSign.GetHeadPosition();
for(index =0;index<MyPatternSign.GetCount();index++)
{
tempPels = MyPatternSign.GetNext(pos);
pointSample.x = tempPels.Red +420;
pointSample.y = 266 - tempPels.Green;
dc.Ellipse(pointSample.x-2,pointSample.y-2,pointSample.x+2,pointSample.y+2);
}
}
break;
case rANDb:
if(!MyPatternPrint.IsEmpty())
{
dc.SelectObject(&newBrush1);
pos = MyPatternPrint.GetHeadPosition();
for(index = 0;index<MyPatternPrint.GetCount();index++)
{
tempPels = MyPatternPrint.GetNext(pos);
pointSample.x = tempPels.Red + 420;
pointSample.y = 266 - tempPels.Blue;
dc.Ellipse(pointSample.x-2,pointSample.y-2,pointSample.x+2,pointSample.y+2);
}
}
if(!MyPatternShade.IsEmpty())
{
dc.SelectObject(&newBrush3);
pos = MyPatternShade.GetHeadPosition();
for(index =0;index<MyPatternShade.GetCount();index++)
{
tempPels = MyPatternShade.GetNext(pos);
pointSample.x = tempPels.Red +420;
pointSample.y = 266 - tempPels.Blue;
dc.Ellipse(pointSample.x-2,pointSample.y-2,pointSample.x+2,pointSample.y+2);
}
}
break;
case bANDg:
if(!MyPatternShade.IsEmpty())
{
dc.SelectObject(&newBrush3);
pos = MyPatternShade.GetHeadPosition();
for(index =0;index<MyPatternShade.GetCount();index++)
{
tempPels = MyPatternShade.GetNext(pos);
pointSample.x = tempPels.Blue +420;
pointSample.y = 266 - tempPels.Green;
dc.Ellipse(pointSample.x-2,pointSample.y-2,pointSample.x+2,pointSample.y+2);
}
}
if(!MyPatternSign.IsEmpty())
{
dc.SelectObject(&newBrush2);
pos = MyPatternSign.GetHeadPosition();
for(index =0;index<MyPatternSign.GetCount();index++)
{
tempPels = MyPatternSign.GetNext(pos);
pointSample.x = tempPels.Blue +420;
pointSample.y = 266 - tempPels.Green;
dc.Ellipse(pointSample.x-2,pointSample.y-2,pointSample.x+2,pointSample.y+2);
}
}
break;
default:
break;
}
}
dc.SelectObject(oldPen);
dc.SelectObject(oldBrush);
}
void CPrintPatView::OnButtonPattenRec()
{
// TODO: Add your control notification handler code here
Pix24Bitmap tempPix;
CDib *m_pDib;
CClientDC m_resultDC(this);
m_pDib = GetDocument()->GetDibPoint();
if(m_RecMode == manual)
{
if(m_drawLinePointsList.GetCount()<2)
{
AfxMessageBox("你还没划线吧",MB_OK,0);
}
else if(m_drawLinePointsList.GetCount()==2)
{
POSITION pos;
pos = m_drawLinePointsList.GetHeadPosition();
POINT point1 = m_drawLinePointsList.GetNext(pos);
POINT point2 = m_drawLinePointsList.GetNext(pos);
TwoPointsToFunc(point1,point2);
CString functionStr;
functionStr.Format("d(w)=%5.2f*x1+(%5.2f)*x2+(%5.2f)",coefficientOfTwo[0],coefficientOfTwo[1],coefficientOfTwo[2]);
m_functionListBox.InsertString(0,functionStr);
for(int j=0;j<m_nHeight;j++)
for(int i=0;i<m_nWidth;i++)
{
tempPix = m_pDib->LoadBitmapIndex(j,i);
switch(m_TwoKindMode)
{
case rANDg:
if(PointDetectTwo(tempPix.Red,tempPix.Green))
m_resultDC.SetPixel(i+30,j+310,RGB(255,255,255));
else
m_resultDC.SetPixel(i+30,j+310,RGB(0,0,0));
break;
case rANDb:
if(PointDetectTwo(tempPix.Red,tempPix.Blue))
m_resultDC.SetPixel(i+30,j+310,RGB(255,255,255));
else
m_resultDC.SetPixel(i+30,j+310,RGB(0,0,0));
break;
case bANDg:
if(PointDetectTwo(tempPix.Blue,tempPix.Green))
m_resultDC.SetPixel(i+30,j+310,RGB(255,255,255));
else
m_resultDC.SetPixel(i+30,j+310,RGB(0,0,0));
break;
default:
break;
}
}
}
}
}
void CPrintPatView::TwoPointsToFunc(POINT point1, POINT point2)
{
coefficientOfTwo[0] = double(1);
coefficientOfTwo[1] = -double(((double)point2.x-(double)point1.x)/((double)point2.y-(double)point1.y));
coefficientOfTwo[2] = -double((coefficientOfTwo[1]*(double)point1.y)+(double)point1.x);
}
BOOL CPrintPatView::PointDetectTwo(int tempx,int tempy)
{
double m_result = coefficientOfTwo[0]*tempx + coefficientOfTwo[1]*tempy + coefficientOfTwo[2];
if(m_result>0)
return TRUE;
else
return FALSE;
}
void CPrintPatView::OnSampleAgain()
{
// TODO: Add your control notification handler code here
coefficientOfTwo[0]=coefficientOfTwo[1]=coefficientOfTwo[2] = 0;
ListIndex = 0;
m_BeginSamp = FALSE;
m_NewlySamp = TRUE;
//清空划线链表
m_drawLinePointsList.RemoveAll();
//清除函数显示
m_functionListBox.ResetContent();
//清除特征显示
m_pattenListBox.ResetContent();
//采样未完成
m_isSampleFinish = FALSE;
m_isSampleFinishCheck.SetCheck(0);
//清除特征链表
MyPatternPrint.RemoveAll();
MyPatternSign.RemoveAll();
MyPatternShade.RemoveAll();
DrawReferenceFrame();
CClientDC dc(this);
for(int j=0;j<m_nHeight;j++)
for(int i=0;i<m_nWidth;i++)
{
dc.SetPixel(i+30,j+310,RGB(255,255,255));
}
ReleaseDC(&dc);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -