コード例 #1
0
// ------------------------------------------------------------------------------------------------
void TempMesh::RemoveDegenerates()
{
	// The strategy is simple: walk the mesh and compute normals using
	// Newell's algorithm. The length of the normals gives the area
	// of the polygons, which is close to zero for lines.

	std::vector<IfcVector3> normals;
	ComputePolygonNormals(normals, false);

	bool drop = false;
	size_t inor = 0;

	std::vector<IfcVector3>::iterator vit = verts.begin();
	for (std::vector<unsigned int>::iterator it = vertcnt.begin(); it != vertcnt.end(); ++inor) {
		const unsigned int pcount = *it;
		
		if (normals[inor].SquareLength() < 1e-10f) {
			it = vertcnt.erase(it);
			vit = verts.erase(vit, vit + pcount);

			drop = true;
			continue;
		}

		vit += pcount;
		++it;
	}

	if(drop) {
		IFCImporter::LogDebug("removing degenerate faces");
	}
}
コード例 #2
0
ファイル: IFCUtil.cpp プロジェクト: BitPuffin/NeoEditor
// ------------------------------------------------------------------------------------------------
void TempMesh::FixupFaceOrientation()
{
	const IfcVector3 vavg = Center();

	std::vector<IfcVector3> normals;
	ComputePolygonNormals(normals);

	size_t c = 0, ofs = 0;
	BOOST_FOREACH(unsigned int cnt, vertcnt) {
		if (cnt>2){
			const IfcVector3& thisvert = verts[c];
			if (normals[ofs]*(thisvert-vavg) < 0) {
				std::reverse(verts.begin()+c,verts.begin()+cnt+c);
			}
		}
		c += cnt;
		++ofs;
	}
}