📄 curversimpleview.cpp
字号:
{
temp=fabs(a*fps[i].pointofxy.x+b*fps[i].pointofxy.y+c);
if(temp>max)
{
max=temp;
id=fps[i].pointID;//最大的为什么会等于0
}
}
if(max>fa)
return 1;
id=fps[fps.size()-1].pointID;
return 0;
}
BOOL CCurverSimpleView::stop()
{
for(int i=0;i<featurepoints.size();i++)
if(featurepoints[i].usedFlag==0)//有未使用的点
return FALSE;
return TRUE;
}
void CCurverSimpleView::GetRCurver(vector<Orignpoint> fps,int idn,float fa)
{
int Q;
int id2=0;
vector<Orignpoint>rpts,lpts;
Q=GetSelectpointID(fps,id2,fa);
if(Q==0)
{
if(fps[fps.size()-1].pointID==idn)
return;
featurepoints[id2].usedFlag=1;
for(int i=id2;i<idn+1;i++)
rpts.push_back(featurepoints[i]);
GetRCurver(rpts,idn,fa);
}
if(Q==1)
{
for(int i=fps[0].pointID;i<id2+1;i++)
lpts.push_back(featurepoints[i]);
GetRCurver(lpts,idn,fa);
}
/*if(Q==0)
return;
if(Q==1)//有暂时特征点
{
for(int i=id0;i<point_id+1;i++)
fps1.push_back(fps[i]);
Q=GetSelectpointID(fps1,point_id2,fa);
if(Q==0)
{
fps[point_id2].usedFlag=1;
for(int j=point_id2;j<fps.size()+1;j++)
fps2.push_back(fps[j]);
GetRCurver(fps2,point_id,point_id2,fa);
}
if(Q==1)
{
for(int i=id0;i<point_id+1;i++)
fps1.push_back(fps[i]);
GetRCurver(fps1,point_id,point_id2,fa);
}
}*/
/* Q=GetSelectpointID(fps,id2,fa);//id2==0?=1
if(Q==0)
{
featurepoints[id2].usedFlag=1;
id1=id2;//保存这个点的ID
for(int i=id2;i<featurepoints.size()-1;i++)//idn==1?
rpts.push_back(featurepoints[i]);
if(FlagEnd==1)
GetRCurver(rpts,0,rpts.size()-1,fa);//!
}
if(Q==1)
{
for(int i=id1;i<id2+1;i++)
lpts.push_back(featurepoints[i]);
GetRCurver(lpts,0,lpts.size()-1,fa);//stackflow
}*/
}
/*void CCurverSimpleView::GetCurverPoints(vector<Orignpoint> fps,int&id,float fa)
{
if(stop())
return;
int Q;
int point_id;
SelectedPoint pt;
vector<Orignpoint>teamppts;
vector<Orignpoint>teampptsn;
Q=GetSelectpointID(fps,point_id,fa);
if(Q==0)
{
/*pt.pointID=featurepoints[point_id].pointID;
pt.pointofxy=featurepoints[point_id].pointofxy;
selectedpoints.push_back(pt);
featurepoints[point_id].usedFlag=1;
return;
}
if(Q==1)
{
for(int i=0;i<point_id+1;i++)
teamppts.push_back(featurepoints[i]);
Q=GetSelectpointID(teamppts,point_id,fa);
if(Q==0)//暂时的特征点变为特征点压入
{
pt.pointID=featurepoints[point_id].pointID;
pt.pointofxy=featurepoints[point_id].pointofxy;
selectedpoints.push_back(pt);
featurepoints[point_id].usedFlag=1;
for(int j=point_id;j<featurepoints.size();j++)
{
teampptsn.push_back(featurepoints[j]);
}
GetCurverPoints(teampptsn,point_id,fa);//!椎overflow
}
if(Q==1)
{
GetCurverPoints(teamppts,point_id,fa);
}
}
}**/
/*void CCurverSimpleView::display(vector<SelectedPoint> pts)
{
float array[M][3];
for(int i=0;i<pts.size();i++)
{
array[i][0]=pts[i].pointofxy.x/100.0;
array[i][1]=pts[i].pointofxy.y/100.0;
array[i][2]=0.0;
}
glMap1f(GL_MAP1_VERTEX_3,0.0,1.0,3,pts.size(),&array[0][0]);
glEnable(GL_MAP1_VERTEX_3);
glShadeModel(GL_FLAT);
glLineWidth(3);
for(i=0;i<pts.size();i++)
{
glBegin(GL_LINE_STRIP);
glColor3f(0.f,1.f,0.f);
glEvalCoord1f((GLfloat)i/20.0);
//glVertex2f(float(pts[i].pointofxy.x)/100.0,float(pts[i].pointofxy.y)/100.0);
}
glEnd();
}*/
void CCurverSimpleView::OnDouglasPeuker()
{
// TODO: Add your command handler code here
CsetValue Dialog;
SelectedPoint pt;
vector<Orignpoint> lpts,rpts;
//int id;
Dialog.DoModal();
fa=Dialog.m_favalue*100;
GetRCurver(featurepoints,featurepoints.size()-1,fa);
//GetCurverPoints(featurepoints,id,fa);
/*int Q=GetSelectpointID(featurepoints,id,fa);
if(Q==0)//则将首末两点放进
{
pt.pointID=featurepoints[0].pointID;
pt.pointofxy=featurepoints[0].pointofxy;
selectedpoints.push_back(pt);
pt.pointID=featurepoints[featurepoints.size()-1].pointID;
pt.pointofxy=featurepoints[featurepoints.size()-1].pointofxy;
selectedpoints.push_back(pt);
}
if(Q==1)
{
//pt.pointID=featurepoints[0].pointID;
//pt.pointofxy=featurepoints[0].pointofxy;
//selectedpoints.push_back(pt);
//pt.pointID=featurepoints[id].pointID;
//pt.pointofxy=featurepoints[id].pointofxy;
for(int i=0;i<id+1;i++)
lpts.push_back(featurepoints[i]);//为何在这里错了
GetRCurver(lpts,0,id,fa);//id=1时
for(i=id;i<featurepoints.size();i++)
rpts.push_back(featurepoints[i]);
GetRCurver(rpts,id,featurepoints.size()-1,fa);
}*/
pt.pointID=featurepoints[0].pointID;
pt.pointofxy=featurepoints[0].pointofxy;
selectedpoints.push_back(pt);
for(int i=1;i<featurepoints.size()-1;i++)
{
if(featurepoints[i].usedFlag==1)
{
pt.pointID=featurepoints[i].pointID;
pt.pointofxy=featurepoints[i].pointofxy;
selectedpoints.push_back(pt);
}
}
pt.pointID=featurepoints[i].pointID;
pt.pointofxy=featurepoints[i].pointofxy;
selectedpoints.push_back(pt);/**/
m_display=TRUE;
//display(selectedpoints);
//selectedpoints.size();
CString str,str2;
str.Format("共获得点%d个,分别为:\n\r",selectedpoints.size());
for(i=0;i<selectedpoints.size();i++)
{
str2.Format("%d",selectedpoints[i].pointID);
str+=str2+"号点,";
}
AfxMessageBox(str);
}
/*void CCurverSimpleView::OnDisplay()
{
// TODO: Add your command handler code here
/*CRect rect;
GetClientRect(&rect);
int cx=rect.right;
int cy=rect.bottom;
m_display=TRUE;
glPushMatrix();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(40.0,double(cx)/double(cy),0.1f,10.f);
glTranslatef(-2.f,-1.8f,-4.f);
glMatrixMode(GL_MODELVIEW);//没有该语句无法显示物体
glPopMatrix();
//display(selectedpoints);
//CClientDC dc(this);
}*/
void CCurverSimpleView::OnClear()
{
// TODO: Add your command handler code here
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
//InvalidateRect(NULL,TRUE);
}
void CCurverSimpleView::OnDrawnewline()
{
// TODO: Add your command handler code here
m_newdraw=TRUE;
}
void CCurverSimpleView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
CPen pen(0,0,RGB(0,255,0));//最后一个参数才表示颜色
CPen *newpen=dc.SelectObject(&pen);
dc.SetROP2(R2_NOT);
/*if(pt!=point&&m_newdraw==TRUE)
{
//dc.MoveTo(ptbegin);
//dc.LineTo(pt);
dc.MoveTo(pt);
dc.LineTo(point);
}
pt=point;*/
if(m_newdraw==TRUE)
{
dc.MoveTo(m_ptStart);
dc.LineTo(m_ptOld);
dc.MoveTo(m_ptStart);
dc.LineTo(point);
}
m_ptOld=point;
CView::OnMouseMove(nFlags, point);
}
void CCurverSimpleView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//dc.SetROP2(R2_NOT);
/*if(pt!=point&&m_newdraw==TRUE)
{
dc.MoveTo(ptbegin);
dc.LineTo(pt);
}
ReleaseCapture();*/
CClientDC dc(this);
CPen pen(0,0,RGB(0,255,0));//最后一个参数才表示颜色
CPen *newpen=dc.SelectObject(&pen);
dc.SetROP2(R2_NOT);
if(m_newdraw)
{
m_newdraw=false;
ReleaseCapture();
ClipCursor(NULL);
//CClientDC dc(this);
dc.MoveTo(m_ptStart);
dc.LineTo(m_ptOld);
dc.SetROP2(R2_COPYPEN);
dc.MoveTo(m_ptStart);
dc.LineTo(point);
}
m_newdraw=false;
CView::OnLButtonUp(nFlags, point);
}
float CCurverSimpleView::computedis(float a,float b,float c,Orignpoint pt)
{
return fabs((a*pt.pointofxy.x+b*pt.pointofxy.y+c));
}
void CCurverSimpleView::distancejuage(float fa)
{
int i=0,j=2,k=1;
float a,b,c;
float dis;
if(m_newdraw=TRUE)
{
//featurepoints2.size();
do
{
CPoint pt1=featurepoints2[i].pointofxy;
CPoint pt2=featurepoints2[j].pointofxy;
GetLineABC(pt1,pt2,a,b,c);
dis=computedis(a,b,c,featurepoints2[k]);
if(dis>fa)
{
featurepoints2[k].usedFlag=1;
i+=1;
if(featurepoints2[i].usedFlag==0)
i+=1;
j=i+2;
k=i+1;
}
else
{
j+=1;
k+=1;
}
}while(j<featurepoints2.size());
}
else
AfxMessageBox("还没有特征点");
}
void CCurverSimpleView::OnJuagedistance()
{
// TODO: Add your command handler code here
float fa;
vector<Orignpoint> pts;
CDC *pDC=GetDC();
CPen pen(0,0,RGB(255,0,0,));
CPen *newpen=pDC->SelectObject(&pen);
CString str;
int count=0;
str="★";
CSetDistancefa dialog;
dialog.DoModal();
fa=dialog.m_disfa*50;
distancejuage(fa);
//r AfxMessageBox
//m_newdrawpt=TRUE;
/*CClientDC dc(this);*/
featurepoints2[0].usedFlag=1;
featurepoints2[featurepoints2.size()-1].usedFlag=1;
/**/for(int i=0;i<featurepoints2.size();i++)
{
if(featurepoints2[i].usedFlag==1)
{
pts.push_back(featurepoints2[i]);
//pDC.TextOut(featurepoints2[i].pointofxy.x,featurepoints2[i].pointofxy.y,str);
pDC->TextOut(featurepoints2[i].pointofxy.x,featurepoints2[i].pointofxy.y,str);}
}
//str.Format("共获得%d个点\n\r",count);
//AfxMessageBox(str);
CPoint pt1,pt2;
for(i=0;i<pts.size()-1;i++)
{
pt1=pts[i].pointofxy;
pt2=pts[i+1].pointofxy;
pDC->MoveTo(pt1);
pDC->LineTo(pt2);
}
m_newdraw=false;//没有这一句不行
}
void CCurverSimpleView::DrawTriangle()
{
if(TrianglePt.size()!=0)
{
CDC *dc=GetDC();
CPen pen(0,0,RGB(255,0,0,));
CPen *newpen=pDC->SelectObject(&pen);
dc->MoveTo(TrianglePt[0]);
dc->LineTo(TrianglePt[1]);
dc->MoveTo(TrianglePt[1]);
dc->LineTo(TrianglePt[2]);
dc->MoveTo(TrianglePt[2]);
dc->LineTo(TrianglePt[0]);
}
return;
}
void CCurverSimpleView::Compute()
{
float a,b,c;
float f1,fi;
//DrawTriangle();
if(TrianglePt.size!=0)
{
TrianglePt[4]=TrianglePt[0];
for(int i=0;i<3;i++)
{
GetLineABC(TrianglePt[i],TrianglePt[i+1],a,b,c);
f1=TrianglePt[TrianglePt.size()-1].x*a+TrianglePt[TrianglePt.size()-1].y*b+c;
fi=TrianglePt[i].x*a+TrianglePt[i].y*b+c;
if(f1*fi>0)
m_b[i]=1;
m_b[i]=0;
}
if(m_b[0]*m_b[1]*m_b[2]==1)
AfxMessageBox("点在三角形内");
else
AfxMessageBox("点不在三角形内");
}
return;
}
void CCurverSimpleView::OnJuagepointinorout()
{
// TODO: Add your command handler code here
if(TrianglePt.size()==0)
AfxMessageBox("请先在屏幕布上输入三角形的三个点");
m_PtInTriangle=1;
}
void CCurverSimpleView::OnDisplayResult()
{
// TODO: Add your command handler code here
if(m_PtInTriangle==2)
Compute();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -