RT
有人遇到过这种问题么,感觉很奇怪,分析逻辑也没发现错误~不知道该如何着手去寻找错误了,代码如下:
void compute_DelaunayTriangulation::get_voronoi_cell(DelaunayTriangulation &DT, CSG_Shapes *input_boundarys)
{
TSG_Point meet_point1,meet_point2;
for (int i=0; i<DT.m_vertices.size(); ++i)
{
std::vector<m_voronoi>::iterator pos;
DelaunayVertex &DV = DT.m_vertices[i];
m_voronoi start,end;
std::vector<m_voronoi> temp;
start = *DV.m_voronoi_cell.begin();
end = DV.m_voronoi_cell[DV.m_voronoi_cell.size()-1];
for (int icell = 0; icell < DV.m_voronoi_cell.size()-1; ++icell)
{
//std::vector<m_voronoi>::const_iterator element = DV.m_voronoi_cell.begin();
int count = 0;
bool mark1=false,mark2=false;
m_voronoi cell_vertex = DV.m_voronoi_cell.at(icell);
m_voronoi cell_vertex_next = DV.m_voronoi_cell.at(icell+1);
mark1 = check_out_boundary(cell_vertex.vertex);
mark2 = check_out_boundary(cell_vertex_next.vertex);
if(mark1 != mark2)
{
if(m_meet(cell_vertex.vertex,cell_vertex_next.vertex,meet_point1)==true)
{
if(mark1==true)
{
DV.m_voronoi_cell.erase(remove(DV.m_voronoi_cell.begin(), DV.m_voronoi_cell.end(), cell_vertex)
,DV.m_voronoi_cell.end());
}
else
{
DV.m_voronoi_cell.erase(remove(DV.m_voronoi_cell.begin(), DV.m_voronoi_cell.end(), cell_vertex_next)
,DV.m_voronoi_cell.end());
}
if (cell_vertex.is_valid == true)
{//拐点增添
double x_min = std::min((double)cell_vertex.vertex.e1(),meet_point1.x);
double x_max = std::max((double)cell_vertex.vertex.e1(),meet_point1.x);
double y_min = std::min((double)cell_vertex.vertex.e2(),meet_point1.y);
double y_max = std::max((double)cell_vertex.vertex.e2(),meet_point1.y);
for (int k = 0; k < boundary.size(); k++)
{
if (boundary[k].e1()>=x_min&&boundary[k].e1()<=x_max
&&boundary[k].e2()>=y_min&&boundary[k].e2()<=y_max)
{
DV.m_voronoi_cell.push_back(boundary[k]);
DV.m_voronoi_cell[DV.m_voronoi_cell.size()-1].is_valid = true;
}
}
}
DV.m_voronoi_cell.push_back(m_voronoi(c2gaPoint(meet_point1.x, meet_point1.y),default_attribute));
DV.m_voronoi_cell[DV.m_voronoi_cell.size()-1].is_valid = true;
count ++;
}
}
if (count == 2)
{
break;
}
}//for
bool mark3 = false,mark4 = false;
mark3 = check_out_boundary(end.vertex);
mark4 = check_out_boundary(start.vertex);
if (mark3 != mark4)
{
if(m_meet(end.vertex,start.vertex,meet_point2))
{
if (mark3 == true)
{
DV.m_voronoi_cell.erase(remove(DV.m_voronoi_cell.begin(), DV.m_voronoi_cell.end(), end)
,DV.m_voronoi_cell.end());
}
else
{
DV.m_voronoi_cell.erase(remove(DV.m_voronoi_cell.begin(), DV.m_voronoi_cell.end(), start)
,DV.m_voronoi_cell.end());
}
DV.m_voronoi_cell.push_back(m_voronoi(c2gaPoint(meet_point2.x, meet_point2.y),default_attribute));
DV.m_voronoi_cell[DV.m_voronoi_cell.size()-1].is_valid = true;
}
}
{//拐点增添
double x_min1 = std::min((double)end.vertex.e1(),meet_point1.x);
double x_max1 = std::max((double)end.vertex.e1(),meet_point1.x);
double y_min1 = std::min((double)end.vertex.e2(),meet_point1.y);
double y_max1 = std::max((double)end.vertex.e2(),meet_point1.y);
for (int k = 0; k < boundary.size(); k++)
{
if (boundary[k].e1()>=x_min1&&boundary[k].e1()<=x_max1
&&boundary[k].e2()>=y_min1&&boundary[k].e2()<=y_max1)
{
DV.m_voronoi_cell.push_back(boundary[k]);
DV.m_voronoi_cell[DV.m_voronoi_cell.size()-1].is_valid = true;
}
}
double x_min2 = std::min((double)end.vertex.e1(),meet_point2.x);
double x_max2 = std::max((double)end.vertex.e1(),meet_point2.x);
double y_min2 = std::min((double)end.vertex.e2(),meet_point2.y);
double y_max2 = std::max((double)end.vertex.e2(),meet_point2.y);
for (int k = 0; k < boundary.size(); k++)
{
if (boundary[k].e1()>=x_min2&&boundary[k].e1()<=x_max2
&&boundary[k].e2()>=y_min2&&boundary[k].e2()<=y_max2)
{
DV.m_voronoi_cell.push_back(boundary[k]);
DV.m_voronoi_cell[DV.m_voronoi_cell.size()-1].is_valid = true;
}
}
}
//去重复
std::sort(DV.m_voronoi_cell.begin(), DV.m_voronoi_cell.end(), sort_vector_op(DV.m_pt));
pos = std::unique(DV.m_voronoi_cell.begin(), DV.m_voronoi_cell.end());
if (pos != DV.m_voronoi_cell.end())
{
DV.m_voronoi_cell.erase(pos, DV.m_voronoi_cell.end());
}
}//for
}