public static gp_Dir ComputeNormal(this TopoDS_Face face) { double umin = 0, umax = 0, vmin = 0, vmax = 0; BRepTools.UVBounds(face, ref umin, ref umax, ref vmin, ref vmax); var surface = BRep_Tool.Surface(face); var props = new GeomLProp_SLProps(surface, umin, vmin, 1.0, 1e-1); return(props.Normal()); }
//-------------------------------------------------------------------------------------------------- void _AddFaceProperties(TopoDS_Face face) { const string facecat = "Face"; const string surfcat = "Surface"; if (Shape != null) { var subshapeRef = Shape.GetSubshapeReference(_TopLevelShape, face); _AddProperty(facecat, "SubshapeRef", subshapeRef?.ToString() ?? "null"); } _AddProperty(facecat, "Tolerance", $"{BRep_Tool.Tolerance(face)}"); _AddProperty(facecat, "Nat.Restrict.", $"{(BRep_Tool.NaturalRestriction(face) ? "Yes" : "No")}"); var props = new GProp_GProps(); BRepGProp.SurfaceProperties(BrepShape, props); _AddProperty(facecat, "Area", $"{props.Mass()}"); var surface = BRep_Tool.Surface(face); if (surface != null) { _AddProperty(surfcat, "Class", surface.GetType().Name.Replace("Geom_", "")); double u1 = 0, u2 = 0, v1 = 0, v2 = 0; surface.Bounds(ref u1, ref u2, ref v1, ref v2); _AddProperty(surfcat, "Bounds U", $"({u1}, {u2})"); _AddProperty(surfcat, "Bounds V", $"({v1}, {v2})"); _AddProperty(surfcat, "Is Closed", $"U={(surface.IsUClosed() ? "Yes" : "No")} V={(surface.IsUClosed() ? "Yes" : "No")}"); if (surface.IsUPeriodic() || surface.IsVPeriodic()) { var s = ""; if (surface.IsUPeriodic()) { s += $"U={surface.UPeriod()} "; } if (surface.IsVPeriodic()) { s += $"V={surface.VPeriod()} "; } _AddProperty(surfcat, "Period", s); } _AddProperty(surfcat, "Continuity", surface.Continuity().ToString().Replace("GeomAbs_", "")); } }
//-------------------------------------------------------------------------------------------------- public static Geom_Surface Surface(this TopoDS_Face face) { return(face == null ? null : BRep_Tool.Surface(face)); }