#include "Point.h"
#include "Line.h"
#include "Triangle.h"
#include "BowyerWatson.h"
CBowyerWatson* CBowyerWatson::m_pBowyerWatson = NULL;
CBowyerWatson::CBowyerWatson()
{
ClearBowyerWatson();
}
CBowyerWatson::~CBowyerWatson()
{
ClearBowyerWatson();
}
CBowyerWatson* CBowyerWatson::GetInstance()
{
if( !m_pBowyerWatson )
m_pBowyerWatson = new CBowyerWatson;
return m_pBowyerWatson;
}
void CBowyerWatson::ClearBowyerWatson()
{
m_bUpdateDrawFlag = false;
std::list<CPoint*>::iterator iter_point = m_lstBowyerWatsonPointList.begin();
while (iter_point != m_lstBowyerWatsonPointList.end())
{
std::list<CPoint*>::iterator iter_pointNext = iter_point;
iter_pointNext++;
SAFE_DELETE(*iter_point);
m_lstBowyerWatsonPointList.erase(iter_point);
iter_point = iter_pointNext;
}//Point
std::list<CLine*>::iterator iter_line = m_lstBowyerWatsonLineList.begin();
while (iter_line != m_lstBowyerWatsonLineList.end())
{
std::list<CLine*>::iterator iter_lineNext = iter_line;
iter_lineNext++;
SAFE_DELETE(*iter_line);
m_lstBowyerWatsonLineList.erase(iter_line);
iter_line = iter_lineNext;
}//line
std::list<CTriangle*>::iterator iter_triangle = m_lstBowyerWatsonTriangleList.begin();
while (iter_triangle != m_lstBowyerWatsonTriangleList.end())
{
std::list<CTriangle*>::iterator iter_triangleNext = iter_triangle;
iter_triangleNext++;
SAFE_DELETE(*iter_triangle);
m_lstBowyerWatsonTriangleList.erase(iter_triangle);
iter_triangle = iter_triangleNext;
}//Triangle
iter_point = m_lstAddPointList.begin();
while (iter_point != m_lstAddPointList.end())
{
std::list<CPoint*>::iterator iter_pointNext = iter_point;
iter_pointNext++;
SAFE_DELETE(*iter_point);
m_lstAddPointList.erase(iter_point);
iter_point = iter_pointNext;
}//Point
}
void CBowyerWatson::CreateHelperPoint(CPoint pt1, CPoint pt2, CPoint pt3, CPoint pt4)
{
mHelperPoints[0] = pt1;
mHelperPoints[1] = pt2;
mHelperPoints[2] = pt3;
mHelperPoints[3] = pt4;
//加入辅助点4个
AddBowyerWatsonPoint(pt1);
AddBowyerWatsonPoint(pt2);
AddBowyerWatsonPoint(pt3);
AddBowyerWatsonPoint(pt4);
//加入辅助窗体的5条边
CLine line1 = CLine(pt1,pt2);
CLine line2 = CLine(pt2,pt3);
CLine line3 = CLine(pt3,pt4);
CLine line4 = CLine(pt4,pt1);
CLine line5 = CLine(pt2,pt4);
AddBowyerWatsonLine(line1);
AddBowyerWatsonLine(line2);
AddBowyerWatsonLine(line3);
AddBowyerWatsonLine(line4);
AddBowyerWatsonLine(line5);
//加入辅助三角形2个
CTriangle tg1 = CTriangle(pt1,pt2,pt4);
CTriangle tg2 = CTriangle(pt2,pt3,pt4);
AddBowyerWatsonTriangle(tg1);
AddBowyerWatsonTriangle(tg2);
}
void CBowyerWatson::AddNewPoint(CPoint pt)
{
bool existflag = false;
std::list<CPoint*>::iterator iter_point = m_lstAddPointList.begin();
for ( ;iter_point != m_lstAddPointList.end();iter_point++)
{
if (pt == (**iter_point))
{
existflag = true;
}
}
if (!existflag)
{
CPoint* newPoint = new CPoint(pt.x,pt.y);
m_lstAddPointList.push_back(newPoint);
}
}
void CBowyerWatson::UpdateNewPoint()
{
std::list<CPoint*>::iterator iter_point = m_lstAddPointList.begin();
while (iter_point != m_lstAddPointList.end())
{
ProcessNewPoint(**iter_point);
std::list<CPoint*>::iterator iter_pointNext = iter_point;
iter_pointNext++;
SAFE_DELETE(*iter_point);
m_lstAddPointList.erase(iter_point);
iter_point = iter_pointNext;
}//Point
//剔除辅助边
std::list<CLine*>::iterator iter = m_lstBowyerWatsonLineList.begin();
while(iter != m_lstBowyerWatsonLineList.end())
{
CLine line = (**iter);
if (line.CheckPointExist(mHelperPoints[0]) || line.CheckPointExist(mHelperPoints[1]) || \
line.CheckPointExist(mHelperPoints[2]) || line.CheckPointExist(mHelperPoints[3]))
{
std::list<CLine*>::iterator iter_next = iter;
iter_next++;
SAFE_DELETE(*iter);
m_lstBowyerWatsonLineList.erase(iter);
iter = iter_next;
}
else{
iter++;
}
}
//剔除辅助三角形
std::list<CTriangle*>::iterator iter_triangle = m_lstBowyerWatsonTriangleList.begin();
while(iter_triangle != m_lstBowyerWatsonTriangleList.end())
{
CTriangle triangle = (**iter_triangle);
if (triangle.CheckPointExist(mHelperPoints[0]) || triangle.CheckPointExist(mHelperPoints[1]) || \
triangle.CheckPointExist(mHelperPoints[2]) || triangle.CheckPointExist(mHelperPoints[3]))
{
std::list<CTriangle*>::iterator iter_nextTriangle = iter_triangle;
iter_nextTriangle++;
SAFE_DELETE(*iter_triangle);
m_lstBowyerWatsonTriangleList.erase(iter_triangle);
iter_triangle = iter_nextTriangle;
}
else{
iter_triangle++;
}
}
}
void CBowyerWatson::AddBowyerWatsonPoint(CPoint pt)
{
bool existflag = false;
std::list<CPoint*>::iterator iter_point = m_lstBowyerWatsonPointList.begin();
for ( ;iter_point != m_lstBowyerWatsonPointList.end();iter_point++)
{
if (pt == (**iter_point))
{
existflag = true;
}
}
if (!existflag)
{
CPoint* newPoint = new CPoint(pt.x,pt.y);
m_lstBowyerWatsonPointList.push_back(newPoint);
}
}
void CBowyerWatson::AddBowyerWatsonLine(CLine line)
{
bool existflag = false;
std::list<CLine*>::iterator iter_line = m_lstBowyerWatsonLineList.begin();
for ( ;iter_line != m_lstBowyerWatsonLineList.end();iter_line++)
{
if (line == (**iter_line))
{
existflag = true;
}
}
if (!existflag)
{
CLine* newLine = new CLine(line.p1,line.p2);
m_lstBowyerWatsonLineList.push_back(newLine);
}
}
void CBowyerWatson::DelBowyerWatsonLine(CLine line)
{
std::list<CLine*>::iterator iter_line = m_lstBowyerWatsonLineList.begin();
while (iter_line != m_lstBowyerWatsonLineList.end())
{
if (line == (**iter_line))
{
SAFE_DELETE(*iter_line);
m_lstBowyerWatsonLineList.erase(iter_line);
break;
}
else
iter_line++;
}//line
std::list<CTriangle*>::iterator iter_Triangle = m_lstBowyerWatsonTriangleList.begin();
while (iter_Triangle != m_lstBowyerWatsonTriangleList.end())
{
if ((*iter_Triangle)->l1 == line || (*iter_Triangle)->l2 == line || (*iter_Triangle)->l3 == line )
{
SAFE_DELETE(*iter_Triangle);
m_lstBowyerWatsonTriangleList.erase(iter_Triangle);
break;
}
else
iter_Triangle++;
}//Triangle
}
void CBowyerWatson::AddBowyerWatsonTriangle(CTriangle triangle)
{
bool existflag = false;
std::list<CTriangle*>::iterator iter_Triangle = m_lstBowyerWatsonTriangleList.begin();
for ( ;iter_Triangle != m_lstBowyerWatsonTriangleList.end();iter_Triangle++)
{
if (triangle == (**iter_Triangle))
{
existflag = true;
}
}
if (!existflag)
{
CTriangle* newTriangle = new CTriangle(triangle.p1,triangle.p2,triangle.p3);
m_lstBowyerWatsonTriangleList.push_back(newTriangle);
}
}
void CBowyerWatson::DelBowyerWatsonTriangle(CTriangle triangle)
{
std::list<CTriangle*>::iterator iter_Triangle = m_lstBowyerWatsonTriangleList.begin();
while (iter_Triangle != m_lstBowyerWatsonTriangleList.end())
{
if (triangle == (**iter_Triangle))
{
SAFE_DELETE(*iter_Triangle);
m_lstBowyerWatsonTriangleList.erase(iter_Triangle);
return;
}
else
iter_Triangle++;
}//line
}
void CBowyerWatson::ProcessNewPoint(CPoint pt)
{
std::list<CLine*> lineList ;
std::list<CTriangle*> triangleList;
std::vector<CTriangle*> commonTriangleVector;
std::list<CLine*>::iterator iter_line = m_lstBowyerWatsonLineList.begin();
for(;iter_line != m_lstBowyerWatsonLineList.end();iter_line++)
{
CLine* newline = new CLine();
memcpy(newline, *iter_line, sizeof(CLine));
lineList.push_back(newline);
}
std::list<CTriangle*>::iterator iter_triangle = m_lstBowyerWatsonTriangleList.begin();
for(;iter_triangle != m_lstBowyerWatsonTriangleList.end();iter_triangle++)
{
CTriangle* newtriangle = new CTriangle();
memcpy(newtriangle, *iter_triangle, sizeo
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Bowyer_Watson.rar (9个子文件)
Bowyer_Watson
Main.cpp 2KB
Triangle.h 581B
BowyerWatson.cpp 13KB
Line.cpp 614B
Point.h 531B
Line.h 495B
Triangle.cpp 3KB
Point.cpp 236B
BowyerWatson.h 1KB
共 9 条
- 1
zzzzyu
- 粉丝: 11
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页