Exemple #1
0
int ReTriangulation::legalizeEdge(std::vector<Vec3f>* point, int pointIdx, Vec2i edge, int triIdx, std::vector<Vec3i>& triangles)
{
	GeometricFunc func;
	int _triIdx;
	int _pointIdx;
	bool flag=true;

	//1. find the triangle that contains the edge
	for(int i=0;i<triangles.size();i++)
	{
		if(func.isTriangleContainEdge(edge, triangles[i]))
		{
			if(i!=triIdx)
			{
				_triIdx=i;
				for(int j=0;j<3;j++)
				{
					if((triangles[i][j]!=edge[0])&&(triangles[i][j]!=edge[1]))
					{
						_pointIdx=triangles[i][j];
						break;
					}
				}
				flag=false;
				break;
			}
		}
	}
	if(flag)
	{
		return 0;
	}
	else
	{
		Vec3f faceNormal=func.computeNormal(point, triangles[_triIdx]);
		Vec3f circumCenter=func.computeCircumcenter(point, triangles[_triIdx], faceNormal);
		float radius=((*point)[edge[0]]-circumCenter).norm();

		if(((*point)[pointIdx]-circumCenter).norm()<radius)
		{
			Vec3i face1=Vec3i(pointIdx, _pointIdx, edge[0]);
			Vec3i face2=Vec3i(pointIdx, _pointIdx, edge[1]);
			Vec3f normal1=func.computeNormal(point, face1);
			if(normal1*faceNormal<0)
			{
				int temp=face1[2];
				face1[2]=face1[1];
				face1[1]=temp;
			}
			else
			{
				int temp=face2[2];
				face2[2]=face2[1];
				face2[1]=temp;
			}

			//replace triangles
			triangles[triIdx]=face1;
			triangles[_triIdx]=face2;

			legalizeEdge(point, pointIdx, Vec2i(_pointIdx, edge[0]), triIdx, triangles);
			legalizeEdge(point, pointIdx, Vec2i(_pointIdx, edge[1]), _triIdx, triangles);
		}
	}
	return 0;
}
Exemple #2
0
void ReTriangulation::legalizeEdge(std::vector<Vec3f>* point, std::vector<Vec2i>& illegalEdge, std::vector<Vec3i>& triangles)
{
	GeometricFunc func;
	int i=0;
	while(1)
	{
		if(illegalEdge.empty())
			break;

		std::vector<int> triIdx;
		std::vector<int> pointIdx;

		if(illegalEdge.size()<=i)
			i=0;
		Vec2i edge=illegalEdge[i];
		
		// illegal한 edge를 포함하는 triangle들을 찾는다
		for(int j=0;j<triangles.size();j++)
		{
			if(func.isTriangleContainEdge(illegalEdge[i], triangles[j]))
			{
				triIdx.push_back(j);
				for(int k=0;k<3;k++)
				{
					if((triangles[j][k]!=edge[0])&&(triangles[j][k]!=edge[1]))
					{
						pointIdx.push_back(triangles[j][k]);
						break;
					}
				}
			}
		}

		if(triIdx.size()==2)
		{
			// 새로 생기는 edge가 illegal edge인지 검사한다.
			Vec2i _edge(pointIdx[0], pointIdx[1]);
			bool flag=true;
			for(int j=0;j<illegalEdge.size();j++)
			{
				if(func.isEdgeSame(illegalEdge[j], _edge))
				{
					flag=false;
					break;
				}
			}
			if(flag)
			{
				triangles[triIdx[0]]=Vec3i(pointIdx[0], pointIdx[1], edge[0]);
				triangles[triIdx[1]]=Vec3i(pointIdx[0], pointIdx[1], edge[1]);
				illegalEdge[i]=illegalEdge[illegalEdge.size()-1];
				illegalEdge.pop_back();
				i--;
			}
		}
		else
		{
			illegalEdge[i]=illegalEdge[illegalEdge.size()-1];
			illegalEdge.pop_back();
			i--;
		}
		i++;
	}
}