def heightmap_from_equation(f, x_min=-1, x_max=1, y_min=-1, y_max=1): """ takes an equation z= f(x,y) and plot the related point cloud as a bspline surface """ print("compute surface") n = 100 # initialize x axis step_x = (x_max - x_min) / n x_ = [] for i in range(n): x_.append(x_min + i * step_x) # initialize y axis step_y = (y_max - y_min) / n y_ = [] for i in range(n): y_.append(y_min + i * step_y) # compute z array = TColgp_Array2OfPnt(1, len(x_), 1, len(y_)) i = 1 for x in x_: j = 1 for y in y_: z = f(x, y) point_to_add = gp_Pnt(x, y, z) array.SetValue(i, j, point_to_add) j += 1 i += 1 print("bspline surface creation") bspl_surface = GeomAPI_PointsToBSplineSurface(array, 3, 8, GeomAbs_C2, 0.001).Surface() display.DisplayShape(bspl_surface, update=True)
def to_tcolgp_array2_pnt(pnts): """ Convert the 2-D array of point_like entities to OCC data. :param array_like pnts: Array of points to convert. :return: OCC array of points. :rtype: TColgp_Array2OfPnt """ pnts = np_array(pnts, dtype=float) n, m = pnts.shape[0:2] gp_pnts = [] for i in range(0, n): row = [] for j in range(0, m): gp = to_gp_pnt(pnts[i, j]) row.append(gp) gp_pnts.append(row) array = TColgp_Array2OfPnt(1, n, 1, m) for i, row in enumerate(gp_pnts, 1): for j, gp in enumerate(row, 1): array.SetValue(i, j, gp) return array
def surf_spl_pcd(px, py, pz): nx, ny = px.shape pnt_2d = TColgp_Array2OfPnt(1, nx, 1, ny) for row in range(pnt_2d.LowerRow(), pnt_2d.UpperRow() + 1): for col in range(pnt_2d.LowerCol(), pnt_2d.UpperCol() + 1): i, j = row - 1, col - 1 pnt = gp_Pnt(px[i, j], py[i, j], pz[i, j]) pnt_2d.SetValue(row, col, pnt) curv = GeomAPI_PointsToBSplineSurface(pnt_2d, 3, 8, GeomAbs_G2, 0.001).Surface() surf = BRepBuilderAPI_MakeFace(curv, 1e-6).Face() return surf, pnt_2d
def load_surface(mesh, surf): nx, ny = surf.shape pnt_2d = TColgp_Array2OfPnt(1, nx, 1, ny) for row in range(pnt_2d.LowerRow(), pnt_2d.UpperRow() + 1): for col in range(pnt_2d.LowerCol(), pnt_2d.UpperCol() + 1): i, j = row - 1, col - 1 pnt = gp_Pnt(mesh[0][i, j], mesh[1][i, j], surf[i, j]) pnt_2d.SetValue(row, col, pnt) surface = GeomAPI_PointsToBSplineSurface(pnt_2d, 3, 8, GeomAbs_G2, 0.001).Surface() srf_face = BRepBuilderAPI_MakeFace(surface, 0, 1, 0, 1, 0.001).Face() return srf_face
def spl_face(px, py, pz): nx, ny = px.shape pnt_2d = TColgp_Array2OfPnt(1, nx, 1, ny) for row in range(pnt_2d.LowerRow(), pnt_2d.UpperRow() + 1): for col in range(pnt_2d.LowerCol(), pnt_2d.UpperCol() + 1): i, j = row - 1, col - 1 pnt = gp_Pnt(px[i, j], py[i, j], pz[i, j]) pnt_2d.SetValue(row, col, pnt) #print (i, j, px[i, j], py[i, j], pz[i, j]) api = GeomAPI_PointsToBSplineSurface(pnt_2d, 3, 8, GeomAbs_G2, 0.001) api.Interpolate(pnt_2d) #surface = BRepBuilderAPI_MakeFace(curve, 1e-6) # return surface.Face() return BRepBuilderAPI_MakeFace(api.Surface(), 1e-6).Face()
def gen_surf(self, rxy=[100, 200], sxy=[0, 0]): surf_x = curvature(self.mesh[0], rxy[0], sxy[0]) surf_y = curvature(self.mesh[1], rxy[1], sxy[1]) self.surf = surf_x + surf_y self.pnt_2d = TColgp_Array2OfPnt(1, self.nx, 1, self.ny) for idx_row in range(self.pnt_2d.LowerRow(), self.pnt_2d.UpperRow() + 1): for idx_col in range(self.pnt_2d.LowerCol(), self.pnt_2d.UpperCol() + 1): row = idx_row - 1 col = idx_col - 1 pnt = gp_Pnt(self.mesh[0][col, row], self.mesh[1][col, row], self.surf[col, row]) self.pnt_2d.SetValue(idx_row, idx_col, pnt)
def bez_face(px, py, pz, axs=gp_Ax3()): nx, ny = px.shape pnt_2d = TColgp_Array2OfPnt(1, nx, 1, ny) for row in range(pnt_2d.LowerRow(), pnt_2d.UpperRow() + 1): for col in range(pnt_2d.LowerCol(), pnt_2d.UpperCol() + 1): i, j = row - 1, col - 1 pnt = gp_Pnt(px[i, j], py[i, j], pz[i, j]) pnt_2d.SetValue(row, col, pnt) #print (i, j, px[i, j], py[i, j], pz[i, j]) surf = Geom_BezierSurface(pnt_2d) # api.Interpolate(pnt_2d) #surface = BRepBuilderAPI_MakeFace(curve, 1e-6) # return surface.Face() face = BRepBuilderAPI_MakeFace(surf, 1e-6).Face() face.Location(set_loc(gp_Ax3(), axs)) return face
def get_surface_sfc(filename): nx, ny = [int(s) for s in getline(filename, 3).split()] xs, ys, xe, ye = [float(s) for s in getline(filename, 2).split()] px = np.linspace(xs, xe, nx) py = np.linspace(ys, ye, ny) mesh = np.meshgrid(px, py) surf = np.loadtxt(filename, skiprows=3).T nx, ny = surf.shape pnt_2d = TColgp_Array2OfPnt(1, nx, 1, ny) for row in range(pnt_2d.LowerRow(), pnt_2d.UpperRow() + 1): for col in range(pnt_2d.LowerCol(), pnt_2d.UpperCol() + 1): i, j = row - 1, col - 1 pnt = gp_Pnt(mesh[0][i, j], mesh[1][i, j], surf[i, j]) pnt_2d.SetValue(row, col, pnt) surface = GeomAPI_PointsToBSplineSurface( pnt_2d, 3, 8, GeomAbs_G2, 0.001).Surface() srf_face = BRepBuilderAPI_MakeFace(surface, 0, 1, 0, 1, 0.001).Face() return srf_face
def build_surf(): p1 = gp_Pnt(-15, 200, 10) p2 = gp_Pnt(5, 204, 0) p3 = gp_Pnt(15, 200, 0) p4 = gp_Pnt(-15, 20, 15) p5 = gp_Pnt(-5, 20, 0) p6 = gp_Pnt(15, 20, 35) array = TColgp_Array2OfPnt(1, 3, 1, 2) array.SetValue(1, 1, p1) array.SetValue(2, 1, p2) array.SetValue(3, 1, p3) array.SetValue(1, 2, p4) array.SetValue(2, 2, p5) array.SetValue(3, 2, p6) bspl_surf = GeomAPI_PointsToBSplineSurface(array, 3, 8, GeomAbs_C2, 0.001).Surface() return bspl_surf
def spl_face(px, py, pz, axs=gp_Ax3()): nx, ny = px.shape pnt_2d = TColgp_Array2OfPnt(1, nx, 1, ny) for row in range(pnt_2d.LowerRow(), pnt_2d.UpperRow() + 1): for col in range(pnt_2d.LowerCol(), pnt_2d.UpperCol() + 1): i, j = row - 1, col - 1 pnt = gp_Pnt(px[i, j], py[i, j], pz[i, j]) pnt_2d.SetValue(row, col, pnt) #print (i, j, px[i, j], py[i, j], pz[i, j]) api = GeomAPI_PointsToBSplineSurface(pnt_2d, 0, 0, GeomAbs_C0, 0.001) api.Interpolate(pnt_2d) #surface = BRepBuilderAPI_MakeFace(curve, 1e-6) # return surface.Face() surf = api.Surface() surf.Transform(set_trf(gp_Ax3(), axs)) face = BRepBuilderAPI_MakeFace(surf, 1e-6).Face() shel = BRepBuilderAPI_MakeShell(surf).Shell() return surf, face, shel
def points2_from_array2(array: TColgp_Array2OfPnt) -> List[List[Point]]: """Construct a list of lists of points from two-dimensional point array. Parameters ---------- array : TColgp_Array2OfPnt Returns ------- list[list[:class:`~compas.geometry.Point`]] """ points = [[None for j in range(array.NbRows())] for i in range(array.NbColumns())] for i in range(array.LowerCol(), array.UpperCol() + 1): for j in range(array.LowerRow(), array.UpperRow() + 1): pnt = array.Value(j, i) points[i - 1][j - 1] = Point(pnt.X(), pnt.Y(), pnt.Z()) return points
def array2_from_points2(points: List[List[Point]]) -> TColgp_Array2OfPnt: """Construct a two-dimensional point array from a list of lists of points. Parameters ---------- points : list[list[:class:`~compas.geometry.Point`]] Returns ------- TColgp_Array2OfPnt """ points = list(zip(* points)) rows = len(points) cols = len(points[0]) array = TColgp_Array2OfPnt(1, rows, 1, cols) for i, row in enumerate(points): for j, point in enumerate(row): array.SetValue(i + 1, j + 1, gp_Pnt(* point)) return array
def np2occ_points(pts): """Converts numpy array of points into occ points array """ if len(pts.shape) == 2: n, m = pts.shape occ_array = TColgp_Array1OfPnt(1, n) for i in range(n): if m == 2: occ_array.SetValue(i + 1, gp_Pnt(pts[i, 0], pts[i, 1], 0.)) elif m == 3: occ_array.SetValue(i + 1, gp_Pnt(pts[i, 0], pts[i, 1], pts[i, 2])) return occ_array elif len(pts.shape) == 3: n, m, _ = pts.shape occ_array = TColgp_Array2OfPnt(1, n, 1, m) for i in range(n): for j in range(m): occ_array.SetValue( i + 1, j + 1, gp_Pnt(pts[i, j, 0], pts[i, j, 1], pts[i, j, 2])) return occ_array else: raise ValueError('Wrong points dimension')
def build_surf(self): p1 = gp_Pnt(-15, 200, 10) p2 = gp_Pnt(5, 204, 0) p3 = gp_Pnt(15, 200, 0) p4 = gp_Pnt(-15, 20, 15) p5 = gp_Pnt(-5, 20, 0) p6 = gp_Pnt(15, 20, 35) self.display.DisplayShape(p1, color="RED") self.display.DisplayShape(p2, color="RED") self.display.DisplayShape(p3, color="RED") self.display.DisplayShape(p4, color="RED") self.display.DisplayShape(p5, color="RED") self.display.DisplayShape(p6, color="RED") array = TColgp_Array2OfPnt(1, 3, 1, 2) array.SetValue(1, 1, p1) array.SetValue(2, 1, p2) array.SetValue(3, 1, p3) array.SetValue(1, 2, p4) array.SetValue(2, 2, p5) array.SetValue(3, 2, p6) self.bspl_surf = GeomAPI_PointsToBSplineSurface( array, 3, 8, GeomAbs_C2, 0.001).Surface() self.bspl_face = BRepBuilderAPI_MakeFace(self.bspl_surf, 1e-6).Face()
def test_bezier_surfaces(self): '''Test: Bezier surfaces''' array1 = TColgp_Array2OfPnt(1, 3, 1, 3) array2 = TColgp_Array2OfPnt(1, 3, 1, 3) array3 = TColgp_Array2OfPnt(1, 3, 1, 3) array4 = TColgp_Array2OfPnt(1, 3, 1, 3) array1.SetValue(1, 1, gp_Pnt(1, 1, 1)) array1.SetValue(1, 2, gp_Pnt(2, 1, 2)) array1.SetValue(1, 3, gp_Pnt(3, 1, 1)) array1.SetValue(2, 1, gp_Pnt(1, 2, 1)) array1.SetValue(2, 2, gp_Pnt(2, 2, 2)) array1.SetValue(2, 3, gp_Pnt(3, 2, 0)) array1.SetValue(3, 1, gp_Pnt(1, 3, 2)) array1.SetValue(3, 2, gp_Pnt(2, 3, 1)) array1.SetValue(3, 3, gp_Pnt(3, 3, 0)) array2.SetValue(1, 1, gp_Pnt(3, 1, 1)) array2.SetValue(1, 2, gp_Pnt(4, 1, 1)) array2.SetValue(1, 3, gp_Pnt(5, 1, 2)) array2.SetValue(2, 1, gp_Pnt(3, 2, 0)) array2.SetValue(2, 2, gp_Pnt(4, 2, 1)) array2.SetValue(2, 3, gp_Pnt(5, 2, 2)) array2.SetValue(3, 1, gp_Pnt(3, 3, 0)) array2.SetValue(3, 2, gp_Pnt(4, 3, 0)) array2.SetValue(3, 3, gp_Pnt(5, 3, 1)) array3.SetValue(1, 1, gp_Pnt(1, 3, 2)) array3.SetValue(1, 2, gp_Pnt(2, 3, 1)) array3.SetValue(1, 3, gp_Pnt(3, 3, 0)) array3.SetValue(2, 1, gp_Pnt(1, 4, 1)) array3.SetValue(2, 2, gp_Pnt(2, 4, 0)) array3.SetValue(2, 3, gp_Pnt(3, 4, 1)) array3.SetValue(3, 1, gp_Pnt(1, 5, 1)) array3.SetValue(3, 2, gp_Pnt(2, 5, 1)) array3.SetValue(3, 3, gp_Pnt(3, 5, 2)) array4.SetValue(1, 1, gp_Pnt(3, 3, 0)) array4.SetValue(1, 2, gp_Pnt(4, 3, 0)) array4.SetValue(1, 3, gp_Pnt(5, 3, 1)) array4.SetValue(2, 1, gp_Pnt(3, 4, 1)) array4.SetValue(2, 2, gp_Pnt(4, 4, 1)) array4.SetValue(2, 3, gp_Pnt(5, 4, 1)) array4.SetValue(3, 1, gp_Pnt(3, 5, 2)) array4.SetValue(3, 2, gp_Pnt(4, 5, 2)) array4.SetValue(3, 3, gp_Pnt(5, 5, 1)) BZ1, BZ2, BZ3, BZ4 = map(Geom_BezierSurface, [array1, array2, array3, array4]) bezierarray = TColGeom_Array2OfBezierSurface(1, 2, 1, 2) bezierarray.SetValue(1, 1, BZ1) bezierarray.SetValue(1, 2, BZ2) bezierarray.SetValue(2, 1, BZ3) bezierarray.SetValue(2, 2, BZ4) BB = GeomConvert_CompBezierSurfacesToBSplineSurface(bezierarray) self.assertTrue(BB.IsDone()) poles = BB.Poles().Array2() uknots = BB.UKnots().Array1() vknots = BB.VKnots().Array1() umult = BB.UMultiplicities().Array1() vmult = BB.VMultiplicities().Array1() udeg = BB.UDegree() vdeg = BB.VDegree() BSPLSURF = Geom_BSplineSurface(poles, uknots, vknots, umult, vmult, udeg, vdeg, False, False) BSPLSURF.Translate(gp_Vec(0, 0, 2))
def parse_face(topo_face): """ Method to parse a single `Face` (a single patch nurbs surface). It returns a matrix with all the coordinates of control points of the `Face` and a second list with all the control points related to the `Edges` of the `Face.` :param Face topo_face: the input Face. :return: control points of the `Face`, control points related to `Edges`. :rtype: tuple(numpy.ndarray, list) """ # get some Face - Edge - Vertex data map information mesh_points_edge = [] face_exp_wire = TopExp_Explorer(topo_face, TopAbs_WIRE) # loop on wires per face while face_exp_wire.More(): twire = topods_Wire(face_exp_wire.Current()) wire_exp_edge = TopExp_Explorer(twire, TopAbs_EDGE) # loop on edges per wire while wire_exp_edge.More(): edge = topods_Edge(wire_exp_edge.Current()) bspline_converter = BRepBuilderAPI_NurbsConvert(edge) bspline_converter.Perform(edge) bspline_tshape_edge = bspline_converter.Shape() h_geom_edge = BRep_Tool_Curve( topods_Edge(bspline_tshape_edge))[0] h_bspline_edge = geomconvert_CurveToBSplineCurve(h_geom_edge) bspline_geom_edge = h_bspline_edge nb_poles = bspline_geom_edge.NbPoles() # Edge geometric properties edge_ctrlpts = TColgp_Array1OfPnt(1, nb_poles) bspline_geom_edge.Poles(edge_ctrlpts) points_single_edge = np.zeros((0, 3)) for i in range(1, nb_poles + 1): ctrlpt = edge_ctrlpts.Value(i) ctrlpt_position = np.array( [[ctrlpt.Coord(1), ctrlpt.Coord(2), ctrlpt.Coord(3)]]) points_single_edge = np.append(points_single_edge, ctrlpt_position, axis=0) mesh_points_edge.append(points_single_edge) wire_exp_edge.Next() face_exp_wire.Next() # extract mesh points (control points) on Face mesh_points_face = np.zeros((0, 3)) # convert Face to Geom B-spline Face nurbs_converter = BRepBuilderAPI_NurbsConvert(topo_face) nurbs_converter.Perform(topo_face) nurbs_face = nurbs_converter.Shape() h_geomsurface = BRep_Tool.Surface(topods.Face(nurbs_face)) h_bsurface = geomconvert_SurfaceToBSplineSurface(h_geomsurface) bsurface = h_bsurface # get access to control points (poles) nb_u = bsurface.NbUPoles() nb_v = bsurface.NbVPoles() ctrlpts = TColgp_Array2OfPnt(1, nb_u, 1, nb_v) bsurface.Poles(ctrlpts) for indice_u_direction in range(1, nb_u + 1): for indice_v_direction in range(1, nb_v + 1): ctrlpt = ctrlpts.Value(indice_u_direction, indice_v_direction) ctrlpt_position = np.array( [[ctrlpt.Coord(1), ctrlpt.Coord(2), ctrlpt.Coord(3)]]) mesh_points_face = np.append(mesh_points_face, ctrlpt_position, axis=0) return mesh_points_face, mesh_points_edge
from OCC.Core.gp import gp_Pnt from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeFace from OCC.Core.TColgp import TColgp_Array2OfPnt from OCC.Core.GeomAPI import GeomAPI_PointsToBSplineSurface from OCC.Core.GeomAbs import GeomAbs_C2 from OCC.Core.ShapeAnalysis import ShapeAnalysis_Surface, shapeanalysis_GetFaceUVBounds p1 = gp_Pnt(-15, 200, 10) p2 = gp_Pnt(5, 204, 0) p3 = gp_Pnt(15, 200, 0) p4 = gp_Pnt(-15, 20, 15) p5 = gp_Pnt(-5, 20, 0) p6 = gp_Pnt(15, 20, 35) array = TColgp_Array2OfPnt(1, 3, 1, 2) array.SetValue(1, 1, p1) array.SetValue(2, 1, p2) array.SetValue(3, 1, p3) array.SetValue(1, 2, p4) array.SetValue(2, 2, p5) array.SetValue(3, 2, p6) bspl_surf = GeomAPI_PointsToBSplineSurface(array, 3, 8, GeomAbs_C2, 0.001).Surface() face = BRepBuilderAPI_MakeFace(bspl_surf, 1e-6).Face() umin, umax, vmin, vmax = shapeanalysis_GetFaceUVBounds(face) print(umin, umax, vmin, vmax)
def convert_surface(surf, convert_2bs=False): surf_t = surf.Face() d2_feat = {"type": surf_map[surf.GetType()]} s_type = d2_feat["type"] if s_type == "Plane": s = surf.Plane() d2_feat["location"] = list(s.Location().Coord()) d2_feat["z_axis"] = list(s.Axis().Direction().Coord()) d2_feat["x_axis"] = list(s.XAxis().Direction().Coord()) d2_feat["y_axis"] = list(s.YAxis().Direction().Coord()) d2_feat["coefficients"] = list(s.Coefficients()) elif s_type == "Cylinder": s = surf.Cylinder() d2_feat["location"] = list(s.Location().Coord()) d2_feat["z_axis"] = list(s.Axis().Direction().Coord()) d2_feat["x_axis"] = list(s.XAxis().Direction().Coord()) d2_feat["y_axis"] = list(s.YAxis().Direction().Coord()) d2_feat["coefficients"] = list(s.Coefficients()) d2_feat["radius"] = s.Radius() elif s_type == "Cone": s = surf.Cone() d2_feat["location"] = list(s.Location().Coord()) d2_feat["z_axis"] = list(s.Axis().Direction().Coord()) d2_feat["x_axis"] = list(s.XAxis().Direction().Coord()) d2_feat["y_axis"] = list(s.YAxis().Direction().Coord()) d2_feat["coefficients"] = list(s.Coefficients()) d2_feat["radius"] = s.RefRadius() d2_feat["angle"] = s.SemiAngle() d2_feat["apex"] = list(s.Apex().Coord()) elif s_type == "Sphere": s = surf.Sphere() d2_feat["location"] = list(s.Location().Coord()) d2_feat["x_axis"] = list(s.XAxis().Direction().Coord()) d2_feat["y_axis"] = list(s.YAxis().Direction().Coord()) d2_feat["coefficients"] = list(s.Coefficients()) d2_feat["radius"] = s.Radius() elif s_type == "Torus": s = surf.Torus() d2_feat["location"] = list(s.Location().Coord()) d2_feat["z_axis"] = list(s.Axis().Direction().Coord()) d2_feat["x_axis"] = list(s.XAxis().Direction().Coord()) d2_feat["y_axis"] = list(s.YAxis().Direction().Coord()) d2_feat["max_radius"] = s.MajorRadius() d2_feat["min_radius"] = s.MinorRadius() elif s_type == "Bezier": print("BEZIER SURF") elif s_type == "BSpline": if not convert_2bs: c = surf.BSpline() else: c = surf _round = lambda x: round(x, 15) d2_feat["trim_domain"] = list(map(_round, breptools_UVBounds(surf_t))) d2_feat["face_domain"] = list(map(_round, c.Bounds())) d2_feat[ "is_trimmed"] = d2_feat["trim_domain"] != d2_feat["face_domain"] c.SetUNotPeriodic() c.SetVNotPeriodic() d2_feat["u_rational"] = c.IsURational() d2_feat["v_rational"] = c.IsVRational() d2_feat["u_closed"] = c.IsUClosed() d2_feat["v_closed"] = c.IsVClosed() d2_feat["continuity"] = c.Continuity() d2_feat["u_degree"] = c.UDegree() d2_feat["v_degree"] = c.VDegree() p = TColgp_Array2OfPnt(1, c.NbUPoles(), 1, c.NbVPoles()) c.Poles(p) points = [] for pi in range(p.ColLength()): elems = [] for pj in range(p.RowLength()): elems.append(list(p.Value(pi + 1, pj + 1).Coord())) points.append(elems) d2_feat["poles"] = points k = TColStd_Array1OfReal(1, c.NbUPoles() + c.UDegree() + 1) c.UKnotSequence(k) knots = [] for ki in range(k.Length()): knots.append(k.Value(ki + 1)) d2_feat["u_knots"] = knots k = TColStd_Array1OfReal(1, c.NbVPoles() + c.VDegree() + 1) c.VKnotSequence(k) knots = [] for ki in range(k.Length()): knots.append(k.Value(ki + 1)) d2_feat["v_knots"] = knots w = TColStd_Array2OfReal(1, c.NbUPoles(), 1, c.NbVPoles()) c.Weights(w) weights = [] for wi in range(w.ColLength()): elems = [] for wj in range(w.RowLength()): elems.append(w.Value(wi + 1, wj + 1)) weights.append(elems) d2_feat["weights"] = weights scale_factor = 1.0 elif s_type == "Revolution": s = surf.AxeOfRevolution() c = surf.BasisCurve() d1_feat = convert_curve(c) d2_feat["location"] = list(s.Location().Coord()) d2_feat["z_axis"] = list(s.Direction().Coord()) d2_feat["curve"] = d1_feat elif s_type == "Extrusion": c = surf.BasisCurve() d1_feat = convert_curve(c) d2_feat["direction"] = list(surf.Direction().Coord()) d2_feat["curve"] = d1_feat else: print("Unsupported type", s_type) return d2_feat
def test_distances(self): '''Test: distances''' array1 = [] array1.append(gp_Pnt(-5, 1, 2)) array1.append(gp_Pnt(-5, 2, 2)) array1.append(gp_Pnt(-5.3, 3, 1)) array1.append(gp_Pnt(-5, 4, 1)) array1.append(gp_Pnt(-5, 5, 2)) SPL1 = GeomAPI_PointsToBSpline( point_list_to_TColgp_Array1OfPnt(array1)).Curve() array2 = [] array2.append(gp_Pnt(4, 1, 2)) array2.append(gp_Pnt(4, 2, 2)) array2.append(gp_Pnt(3.7, 3, 1)) array2.append(gp_Pnt(4, 4, 1)) array2.append(gp_Pnt(4, 5, 2)) SPL2 = GeomAPI_PointsToBSpline( point_list_to_TColgp_Array1OfPnt(array2)).Curve() aGeomFill1 = GeomFill_BSplineCurves(SPL1, SPL2, GeomFill_StretchStyle) aSurf1 = aGeomFill1.Surface() array3 = TColgp_Array2OfPnt(1, 5, 1, 5) array3.SetValue(1, 1, gp_Pnt(-4, -4, 5)) array3.SetValue(1, 2, gp_Pnt(-4, -2, 5)) array3.SetValue(1, 3, gp_Pnt(-4, 0, 4)) array3.SetValue(1, 4, gp_Pnt(-4, 2, 5)) array3.SetValue(1, 5, gp_Pnt(-4, 4, 5)) array3.SetValue(2, 1, gp_Pnt(-2, -4, 4)) array3.SetValue(2, 2, gp_Pnt(-2, -2, 4)) array3.SetValue(2, 3, gp_Pnt(-2, 0, 4)) array3.SetValue(2, 4, gp_Pnt(-2, 2, 4)) array3.SetValue(2, 5, gp_Pnt(-2, 5, 4)) array3.SetValue(3, 1, gp_Pnt(0, -4, 3.5)) array3.SetValue(3, 2, gp_Pnt(0, -2, 3.5)) array3.SetValue(3, 3, gp_Pnt(0, 0, 3.5)) array3.SetValue(3, 4, gp_Pnt(0, 2, 3.5)) array3.SetValue(3, 5, gp_Pnt(0, 5, 3.5)) array3.SetValue(4, 1, gp_Pnt(2, -4, 4)) array3.SetValue(4, 2, gp_Pnt(2, -2, 4)) array3.SetValue(4, 3, gp_Pnt(2, 0, 3.5)) array3.SetValue(4, 4, gp_Pnt(2, 2, 5)) array3.SetValue(4, 5, gp_Pnt(2, 5, 4)) array3.SetValue(5, 1, gp_Pnt(4, -4, 5)) array3.SetValue(5, 2, gp_Pnt(4, -2, 5)) array3.SetValue(5, 3, gp_Pnt(4, 0, 5)) array3.SetValue(5, 4, gp_Pnt(4, 2, 6)) array3.SetValue(5, 5, gp_Pnt(4, 5, 5)) aSurf2 = GeomAPI_PointsToBSplineSurface(array3).Surface() ESS = GeomAPI_ExtremaSurfaceSurface(aSurf1, aSurf2) dist = ESS.LowerDistance() self.assertGreater(dist, 1.25) self.assertLess(dist, 1.26) a, b = gp_Pnt(), gp_Pnt() ESS.NearestPoints(a, b) NbExtrema = ESS.NbExtrema() for k in range(1, NbExtrema + 1): P3, P4 = gp_Pnt(), gp_Pnt() ESS.Points(k, P3, P4) aCurve = GC_MakeSegment(P3, P4).Value() self.assertFalse(aCurve is None)
def face(): p1 = gp_Pnt() p2 = gp_Pnt() p3 = gp_Pnt() p4 = gp_Pnt() p5 = gp_Pnt() p6 = gp_Pnt() # The white Face sphere = gp_Sphere(gp_Ax3(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0)), 150) green_face = BRepBuilderAPI_MakeFace(sphere, 0.1, 0.7, 0.2, 0.9) # The red face p1.SetCoord(-15, 200, 10) p2.SetCoord(5, 204, 0) p3.SetCoord(15, 200, 0) p4.SetCoord(-15, 20, 15) p5.SetCoord(-5, 20, 0) p6.SetCoord(15, 20, 35) array = TColgp_Array2OfPnt(1, 3, 1, 2) array.SetValue(1, 1, p1) array.SetValue(2, 1, p2) array.SetValue(3, 1, p3) array.SetValue(1, 2, p4) array.SetValue(2, 2, p5) array.SetValue(3, 2, p6) curve = GeomAPI_PointsToBSplineSurface(array, 3, 8, GeomAbs_C2, 0.001).Surface() red_face = BRepBuilderAPI_MakeFace(curve, 1e-6) #The brown face circle = gp_Circ(gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0)), 80) Edge1 = BRepBuilderAPI_MakeEdge(circle, 0, math.pi) Edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(0, 0, -80), gp_Pnt(0, -10, 40)) Edge3 = BRepBuilderAPI_MakeEdge(gp_Pnt(0, -10, 40), gp_Pnt(0, 0, 80)) ##TopoDS_Wire YellowWire MW1 = BRepBuilderAPI_MakeWire(Edge1.Edge(), Edge2.Edge(), Edge3.Edge()) assert MW1.IsDone() yellow_wire = MW1.Wire() brown_face = BRepBuilderAPI_MakeFace(yellow_wire) #The pink face p1.SetCoord(35, -200, 40) p2.SetCoord(50, -204, 30) p3.SetCoord(65, -200, 30) p4.SetCoord(35, -20, 45) p5.SetCoord(45, -20, 30) p6.SetCoord(65, -20, 65) array2 = TColgp_Array2OfPnt(1, 3, 1, 2) array2.SetValue(1, 1, p1) array2.SetValue(2, 1, p2) array2.SetValue(3, 1, p3) array2.SetValue(1, 2, p4) array2.SetValue(2, 2, p5) array2.SetValue(3, 2, p6) BSplineSurf = GeomAPI_PointsToBSplineSurface(array2, 3, 8, GeomAbs_C2, 0.001) aFace = BRepBuilderAPI_MakeFace(BSplineSurf.Surface(), 1e-6).Face() ## ##//2d lines P12d = gp_Pnt2d(0.9, 0.1) P22d = gp_Pnt2d(0.2, 0.7) P32d = gp_Pnt2d(0.02, 0.1) ## line1 = Geom2d_Line(P12d, gp_Dir2d((0.2 - 0.9), (0.7 - 0.1))) line2 = Geom2d_Line(P22d, gp_Dir2d((0.02 - 0.2), (0.1 - 0.7))) line3 = Geom2d_Line(P32d, gp_Dir2d((0.9 - 0.02), (0.1 - 0.1))) ## ##//Edges are on the BSpline surface Edge1 = BRepBuilderAPI_MakeEdge(line1, BSplineSurf.Surface(), 0, P12d.Distance(P22d)).Edge() Edge2 = BRepBuilderAPI_MakeEdge(line2, BSplineSurf.Surface(), 0, P22d.Distance(P32d)).Edge() Edge3 = BRepBuilderAPI_MakeEdge(line3, BSplineSurf.Surface(), 0, P32d.Distance(P12d)).Edge() ## Wire1 = BRepBuilderAPI_MakeWire(Edge1, Edge2, Edge3).Wire() Wire1.Reverse() pink_face = BRepBuilderAPI_MakeFace(aFace, Wire1).Face() breplib_BuildCurves3d(pink_face) display.DisplayColoredShape(green_face.Face(), 'GREEN') display.DisplayColoredShape(red_face.Face(), 'RED') display.DisplayColoredShape(pink_face, Quantity_Color(Quantity_NOC_PINK)) display.DisplayColoredShape(brown_face.Face(), 'BLUE') display.DisplayColoredShape(yellow_wire, 'YELLOW', update=True)
def opencascade_array2_of_pnt(arr): ret = TColgp_Array2OfPnt(1, len(arr), 1, len(arr[0])) for r in range(len(arr)): for c in range(len(arr[0])): ret.SetValue(r + 1, c + 1, to_Pnt(arr[r][c])) return ret