示例#1
0
    def __init__(self, show=None):
        if show != None:
            plotocc.__init__(self)
        self.pt = np.linspace(0, 2 * np.pi, 100)

        self.hz = 15.0
        self.rt = 2.0
        self.r_xy = 30.0
        self.radi = 100
        self.px = 30.0 * np.cos(self.pt)
        self.py = 30.0 * np.sin(self.pt)
        self.pz = 15 * np.cos(5 * self.pt)

        curv_pts, curv_shp = spl_curv(self.px, self.py, self.pz)
        crv1_pts, crv1_shp = self.sin_curv_x(10, 30, pos=-10, scale=2)
        crv2_pts, crv2_shp = self.sin_curv_x(20, 40, pos=+10, scale=1)
        crv3_pts, crv3_shp = self.sin_curv_y(0, 30, pos=0)
        api = GeomFill_BSplineCurves(crv1_shp, crv2_shp, GeomFill_CoonsStyle)

        # self.show_pts_1d(curv_pts)
        # self.display.DisplayShape(curv_shp)

        #self.show_pts_1d(crv1_pts)
        #self.show_pts_1d(crv2_pts)
        #self.show_pts_1d(crv3_pts)
        self.display.DisplayShape(crv1_shp)
        self.display.DisplayShape(crv2_shp)
        self.display.DisplayShape(api.Surface())
    def test_surfaces_from_offsets(self):
        '''Test: surfaces from offsets'''
        array1 = []
        array1.append(gp_Pnt(-4, 5, 5))
        array1.append(gp_Pnt(-3, 6, 6))
        array1.append(gp_Pnt(-1, 7, 7))
        array1.append(gp_Pnt(0, 8, 8))
        array1.append(gp_Pnt(2, 9, 9))
        SPL1 = GeomAPI_PointsToBSpline(
            point_list_to_TColgp_Array1OfPnt(array1)).Curve()

        array2 = []
        array2.append(gp_Pnt(-4, 5, 2))
        array2.append(gp_Pnt(-3, 6, 3))
        array2.append(gp_Pnt(-1, 7, 4))
        array2.append(gp_Pnt(0, 8, 5))
        array2.append(gp_Pnt(2, 9, 6))
        SPL2 = GeomAPI_PointsToBSpline(
            point_list_to_TColgp_Array1OfPnt(array2)).Curve()

        aGeomFill1 = GeomFill_BSplineCurves(SPL1, SPL2, GeomFill_StretchStyle)
        aGeomSurface = aGeomFill1.Surface()

        offset = 1
        GOS = Geom_OffsetSurface(aGeomSurface, offset)
        offset = 2
        GOS1 = Geom_OffsetSurface(aGeomSurface, offset)
        offset = 3
        GOS2 = Geom_OffsetSurface(aGeomSurface, offset)

        face1 = make_face(aGeomSurface)
        face2 = make_face(GOS)
        face3 = make_face(GOS1)
        face4 = make_face(GOS2)
    def test_surface_from_curves(self):
        '''Test: surfaces from curves'''
        array = []
        array.append(gp_Pnt(-4, 0, 2))
        array.append(gp_Pnt(-7, 2, 2))
        array.append(gp_Pnt(-6, 3, 1))
        array.append(gp_Pnt(-4, 3, -1))
        array.append(gp_Pnt(-3, 5, -2))

        aaa = point_list_to_TColgp_Array1OfPnt(array)
        SPL1 = GeomAPI_PointsToBSpline(aaa).Curve()

        a2 = []
        a2.append(gp_Pnt(-4, 0, 2))
        a2.append(gp_Pnt(-2, 2, 0))
        a2.append(gp_Pnt(2, 3, -1))
        a2.append(gp_Pnt(3, 7, -2))
        a2.append(gp_Pnt(4, 9, -1))
        bbb = point_list_to_TColgp_Array1OfPnt(a2)
        SPL2 = GeomAPI_PointsToBSpline(bbb).Curve()

        aGeomFill1 = GeomFill_BSplineCurves(SPL1, SPL2, GeomFill_StretchStyle)

        SPL3 = Geom_BSplineCurve.DownCast(SPL1.Translated(gp_Vec(10, 0, 0)))
        SPL4 = Geom_BSplineCurve.DownCast(SPL2.Translated(gp_Vec(10, 0, 0)))
        aGeomFill2 = GeomFill_BSplineCurves(SPL3, SPL4, GeomFill_CoonsStyle)

        SPL5 = Geom_BSplineCurve.DownCast(SPL1.Translated(gp_Vec(20, 0, 0)))
        SPL6 = Geom_BSplineCurve.DownCast(SPL2.Translated(gp_Vec(20, 0, 0)))
        aGeomFill3 = GeomFill_BSplineCurves(SPL5, SPL6, GeomFill_CurvedStyle)

        aBSplineSurface1 = aGeomFill1.Surface()
        aBSplineSurface2 = aGeomFill2.Surface()
        aBSplineSurface3 = aGeomFill3.Surface()
示例#4
0
def surface_from_curves():
    '''
    @param display:
    '''
    # First spline
    array = []
    array.append(gp_Pnt(-4, 0, 2))
    array.append(gp_Pnt(-7, 2, 2))
    array.append(gp_Pnt(-6, 3, 1))
    array.append(gp_Pnt(-4, 3, -1))
    array.append(gp_Pnt(-3, 5, -2))

    pt_list1 = point_list_to_TColgp_Array1OfPnt(array)
    SPL1 = GeomAPI_PointsToBSpline(pt_list1).Curve()
    SPL1_c = SPL1.GetObject()

    # Second spline
    a2 = []
    a2.append(gp_Pnt(-4, 0, 2))
    a2.append(gp_Pnt(-2, 2, 0))
    a2.append(gp_Pnt(2, 3, -1))
    a2.append(gp_Pnt(3, 7, -2))
    a2.append(gp_Pnt(4, 9, -1))
    pt_list2 = point_list_to_TColgp_Array1OfPnt(a2)
    SPL2 = GeomAPI_PointsToBSpline(pt_list2).Curve()
    SPL2_c = SPL2.GetObject()

    # Fill with StretchStyle
    aGeomFill1 = GeomFill_BSplineCurves(SPL1,
                                        SPL2,
                                        GeomFill_StretchStyle)

    SPL3 = Handle_Geom_BSplineCurve_DownCast(SPL1_c.Translated(gp_Vec(10, 0, 0)))
    SPL4 = Handle_Geom_BSplineCurve_DownCast(SPL2_c.Translated(gp_Vec(10, 0, 0)))
    # Fill with CoonsStyle
    aGeomFill2 = GeomFill_BSplineCurves(SPL3,
                                        SPL4,
                                        GeomFill_CoonsStyle)
    SPL5 = Handle_Geom_BSplineCurve_DownCast(SPL1_c.Translated(gp_Vec(20, 0, 0)))
    SPL6 = Handle_Geom_BSplineCurve_DownCast(SPL2_c.Translated(gp_Vec(20, 0, 0)))
    # Fill with CurvedStyle
    aGeomFill3 = GeomFill_BSplineCurves(SPL5,
                                        SPL6,
                                        GeomFill_CurvedStyle)

    aBSplineSurface1 = aGeomFill1.Surface()
    aBSplineSurface2 = aGeomFill2.Surface()
    aBSplineSurface3 = aGeomFill3.Surface()
    
    display.DisplayShape(make_face(aBSplineSurface1, 1e-6))
    display.DisplayShape(make_face(aBSplineSurface2, 1e-6))
    display.DisplayShape(make_face(aBSplineSurface3, 1e-6), update=True)
示例#5
0
    def from_fill(cls,
                  curve1,
                  curve2,
                  curve3=None,
                  curve4=None,
                  style='stretch'):
        """Construct a NURBS surface from the infill between two, three or four contiguous NURBS curves.

        Parameters
        ----------
        curve1 : :class:`~compas_occ.geometry.OCCNurbsCurve`
        curve2 : :class:`~compas_occ.geometry.OCCNurbsCurve`
        curve3 : :class:`~compas_occ.geometry.OCCNurbsCurve`, optional.
        curve4 : :class:`~compas_occ.geometry.OCCNurbsCurve`, optional.
        style : Literal['stretch', 'coons', 'curved'], optional.

            * ``'stretch'`` produces the flattest patch.
            * ``'curved'`` produces a rounded patch.
            * ``'coons'`` is between stretch and coons.

        Raises
        ------
        ValueError
            If the fill style is not supported.

        Returns
        -------
        :class:`OCCNurbsSurface`

        """

        if style == 'stretch':
            style = GeomFill_StretchStyle
        elif style == 'coons':
            style = GeomFill_CoonsStyle
        elif style == 'curved':
            style = GeomFill_CurvedStyle
        else:
            ValueError('Scheme is not supported')

        surface = cls()
        if curve3 and curve4:
            occ_fill = GeomFill_BSplineCurves(curve1.occ_curve,
                                              curve2.occ_curve,
                                              curve3.occ_curve,
                                              curve4.occ_curve, style)
        elif curve3:
            occ_fill = GeomFill_BSplineCurves(curve1.occ_curve,
                                              curve2.occ_curve,
                                              curve3.occ_curve, style)
        else:
            occ_fill = GeomFill_BSplineCurves(curve1.occ_curve,
                                              curve2.occ_curve, style)
        surface.occ_surface = occ_fill.Surface()
        return surface
示例#6
0
def make_coons(edges):
    from OCC.Core.GeomFill import GeomFill_BSplineCurves, GeomFill_StretchStyle
    if len(edges) == 4:
        spl1, spl2, spl3, spl4 = edges
        srf = GeomFill_BSplineCurves(spl1, spl2, spl3, spl4,
                                     GeomFill_StretchStyle)
    elif len(edges) == 3:
        spl1, spl2, spl3 = edges
        srf = GeomFill_BSplineCurves(spl1, spl2, spl3, GeomFill_StretchStyle)
    elif len(edges) == 2:
        spl1, spl2 = edges
        srf = GeomFill_BSplineCurves(spl1, spl2, GeomFill_StretchStyle)
    else:
        raise ValueError('give 2,3 or 4 curves')
    return srf.Surface()
示例#7
0
    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)
示例#8
0
a1 = []
a1.append(gp_Pnt(-4, 0, 2))
a1.append(gp_Pnt(-7, 2, 2))
a1.append(gp_Pnt(-6, 3, 1))
a1.append(gp_Pnt(-4, 3, -1))
a1.append(gp_Pnt(-3, 5, -2))

pt_list1 = point_list_to_TColgp_Array1OfPnt(a1)
SPL1 = GeomAPI_PointsToBSpline(pt_list1).Curve()

a2 = []
a2.append(gp_Pnt(-4, 0, 2))
a2.append(gp_Pnt(-2, 2, 0))
a2.append(gp_Pnt(2, 3, -1))
a2.append(gp_Pnt(3, 7, -2))
a2.append(gp_Pnt(4, 9, -1))

pt_list2 = point_list_to_TColgp_Array1OfPnt(a2)
SPL2 = GeomAPI_PointsToBSpline(pt_list2).Curve()

fill = GeomFill_BSplineCurves(SPL1, SPL2, GeomFill_CoonsStyle)
surface = fill.Surface()
face = topods_Face(BRepBuilderAPI_MakeFace(surface, 1e-6).Shape())

step_writer = STEPControl_Writer()
Interface_Static_SetCVal("write.step.schema", "AP203")

step_writer.Transfer(face, STEPControl_AsIs)
status = step_writer.Write("surface1.stp")