TopoDS_Face FaceTypedCylinder::buildFace(const FaceVectorType &faces) const { static TopoDS_Face dummy; std::vector<EdgeVectorType> boundaries; boundarySplit(faces, boundaries); if (boundaries.size() < 1) return dummy; //make wires std::vector<TopoDS_Wire> wires; std::vector<EdgeVectorType>::iterator boundaryIt; for (boundaryIt = boundaries.begin(); boundaryIt != boundaries.end(); ++boundaryIt) { BRepLib_MakeWire wireMaker; EdgeVectorType::iterator it; for (it = (*boundaryIt).begin(); it != (*boundaryIt).end(); ++it) wireMaker.Add(*it); if (wireMaker.Error() != BRepLib_WireDone) return dummy; wires.push_back(wireMaker.Wire()); } if (wires.size() < 1) return dummy; std::sort(wires.begin(), wires.end(), ModelRefine::WireSort()); //make face from surface and outer wire. Handle(Geom_CylindricalSurface) surface = Handle(Geom_CylindricalSurface)::DownCast(BRep_Tool::Surface(faces.at(0))); std::vector<TopoDS_Wire>::iterator wireIt; wireIt = wires.begin(); BRepBuilderAPI_MakeFace faceMaker(surface, *wireIt); if (!faceMaker.IsDone()) return dummy; //add additional boundaries. for (wireIt++; wireIt != wires.end(); ++wireIt) { faceMaker.Add(*wireIt); if (!faceMaker.IsDone()) return dummy; } //fix newly constructed face. Orientation doesn't seem to get fixed the first call. ShapeFix_Face faceFixer(faceMaker.Face()); faceFixer.SetContext(new ShapeBuild_ReShape()); faceFixer.Perform(); if (faceFixer.Status(ShapeExtend_FAIL)) return dummy; faceFixer.FixOrientation(); faceFixer.Perform(); if (faceFixer.Status(ShapeExtend_FAIL)) return dummy; return faceFixer.Face(); }
TopoDS_Face FaceTypedCylinder::buildFace(const FaceVectorType &faces) const { std::vector<EdgeVectorType> boundaries; boundarySplit(faces, boundaries); static TopoDS_Face dummy; if (boundaries.size() < 1) return dummy; //take one face and remove all the wires. TopoDS_Face workFace = faces.at(0); ShapeBuild_ReShape reshaper; TopExp_Explorer it; for (it.Init(workFace, TopAbs_WIRE); it.More(); it.Next()) reshaper.Remove(it.Current()); workFace = TopoDS::Face(reshaper.Apply(workFace)); if (workFace.IsNull()) return TopoDS_Face(); ShapeFix_Face faceFixer(workFace); //makes wires std::vector<EdgeVectorType>::iterator boundaryIt; for (boundaryIt = boundaries.begin(); boundaryIt != boundaries.end(); ++boundaryIt) { BRepLib_MakeWire wireMaker; EdgeVectorType::iterator it; for (it = (*boundaryIt).begin(); it != (*boundaryIt).end(); ++it) wireMaker.Add(*it); if (wireMaker.Error() != BRepLib_WireDone) continue; faceFixer.Add(wireMaker.Wire()); } if (faceFixer.Perform() > ShapeExtend_DONE5) return TopoDS_Face(); faceFixer.FixOrientation(); if (faceFixer.Perform() > ShapeExtend_DONE5) return TopoDS_Face(); return faceFixer.Face(); }