예제 #1
0
def mesh_edge(a_topods_edge):
    """ Take a TopoDS_Edge and returns a list of points
    """
    edg = topods_Edge(a_topods_edge)
    assert not edg.IsNull()  # This might be to remove
    # build a curve from the edge
    curve_handle, U1, U2 = BRep_Tool_Curve(edg)
    curve = curve_handle.GetObject()
    if curve is None:
        return False
    IS_LINE = curve.IsInstance('Geom_Line')
    points = []
    if IS_LINE:
        p1 = curve.Value(U1)
        p2 = curve.Value(U2)
        points.append(p1.Coord())
        points.append(p2.Coord())
    else:
        U = U1
        nbp = 10  # this is related to edge quality. TODO: compute the best quality
        dU = (U2 - U1)/nbp
        while U <= U2:
            p = curve.Value(U)
            points.append(p.Coord())
            U += dU
    return points
 def test_Standard_Type(self) -> None:
     """ test that Standard_Type returns the correct type name
     """
     edge = BRepBuilderAPI_MakeEdge(gp_Pnt(0, 0, 0), gp_Pnt(1, 0, 0)).Edge()
     curve, _, _ = BRep_Tool_Curve(edge)
     line = Geom_Line.DownCast(curve)
     self.assertEqual(line.DynamicType().Name(), "Geom_Line")
 def test_downcast_curve(self) -> None:
     """Test if a GeomCurve can be DownCasted to a GeomLine"""
     edge = BRepBuilderAPI_MakeEdge(gp_Pnt(0, 0, 0), gp_Pnt(1, 0, 0)).Edge()
     curve, _, _ = BRep_Tool_Curve(edge)
     self.assertTrue(isinstance(curve, Geom_Curve))
     # The edge is internally a line, so we should be able to downcast it
     line = Geom_Line.DownCast(curve)
     self.assertTrue(isinstance(line, Geom_Curve))
     # Hence, it should not be possible to downcast it as a B-Spline curve
     bspline = Geom_BSplineCurve.DownCast(curve)
     self.assertTrue(bspline is None)
예제 #4
0
    def _bspline_curve_from_wire(self, wire):
        """
        Private method that takes a TopoDS_Wire and transforms it into a
        Bspline_Curve.

        :param TopoDS_Wire wire: the TopoDS_Face to be converted
        :rtype: Geom_BSplineSurface
        """
        if not isinstance(wire, TopoDS_Wire):
            raise TypeError("wire must be a TopoDS_Wire")

        # joining all the wire edges in a single curve here
        # composite curve builder (can only join Bspline curves)
        composite_curve_builder = GeomConvert_CompCurveToBSplineCurve()

        # iterator to edges in the TopoDS_Wire
        edge_explorer = TopExp_Explorer(wire, TopAbs_EDGE)
        while edge_explorer.More():
            # getting the edge from the iterator
            edge = topods_Edge(edge_explorer.Current())

            # edge can be joined only if it is not degenerated (zero length)
            if BRep_Tool.Degenerated(edge):
                edge_explorer.Next()
                continue

            # the edge must be converted to Nurbs edge
            nurbs_converter = BRepBuilderAPI_NurbsConvert(edge)
            nurbs_converter.Perform(edge)
            nurbs_edge = topods_Edge(nurbs_converter.Shape())

            # here we extract the underlying curve from the Nurbs edge
            nurbs_curve = BRep_Tool_Curve(nurbs_edge)[0]

            # we convert the Nurbs curve to Bspline curve
            bspline_curve = geomconvert_CurveToBSplineCurve(nurbs_curve)

            # we can now add the Bspline curve to the composite wire curve
            composite_curve_builder.Add(bspline_curve, self.tolerance)
            edge_explorer.Next()

        # GeomCurve obtained by the builder after edges are joined
        comp_curve = composite_curve_builder.BSplineCurve()
        return comp_curve
예제 #5
0
    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