##Copyright 2009-2015 Thomas Paviot (tpaviot@gmail.com) ## ##This file is part of pythonOCC. ## ##pythonOCC is free software: you can redistribute it and/or modify ##it under the terms of the GNU Lesser General Public License as published by ##the Free Software Foundation, either version 3 of the License, or ##(at your option) any later version. ## ##pythonOCC is distributed in the hope that it will be useful, ##but WITHOUT ANY WARRANTY; without even the implied warranty of ##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##GNU Lesser General Public License for more details. ## ##You should have received a copy of the GNU Lesser General Public License ##along with pythonOCC. If not, see . import math import random from OCC.gp import gp_Pnt, gp_Lin, gp_Ax1, gp_Dir, gp_Elips, gp_Ax2 from OCC.BRepBuilderAPI import (BRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeVertex, BRepBuilderAPI_MakeWire) from OCC.BRepFill import (BRepFill_OffsetWire) from OCC.BRepOffsetAPI import BRepOffsetAPI_MakeOffset from OCC.TColgp import TColgp_Array1OfPnt from OCC.TColStd import TColStd_Array1OfReal from OCC.GeomAPI import GeomAPI_Interpolate, GeomAPI_PointsToBSpline from OCC.TColgp import TColgp_HArray1OfPnt2d, TColgp_Array1OfPnt2d from OCC.TColGeom import TColGeom_Array1OfBezierCurve from OCC.TopoDS import TopoDS_Wire from OCC.GeomAPI import GeomAPI_PointsToBSpline from core_geometry_utils import point_list_to_TColgp_Array1OfPnt, make_face from OCC.GeomConvert import GeomConvert_BSplineCurveToBezierCurve from OCC.ShapeUpgrade import ShapeUpgrade_ConvertCurve3dToBezier from OCC.GeomConvert import GeomConvert_BSplineSurfaceToBezierSurface from OCC.BRepOffsetAPI import BRepOffsetAPI_ThruSections from OCC.Geom import Geom_BezierCurve from OCC.Geom import Geom_OffsetCurve from OCC.GeomAbs import GeomAbs_Arc from OCC.GeomFill import (GeomFill_BSplineCurves, GeomFill_StretchStyle, GeomFill_CoonsStyle, GeomFill_CurvedStyle) from OCC.GeomAPI import GeomAPI_PointsToBSpline from OCC.Geom import Handle_Geom_BSplineCurve_DownCast from OCC.Display.SimpleGui import init_display display, start_display, add_menu, add_function_to_menu = init_display() def test(event=None): display.Context.SetDeviationAngle(0.00001) # 0.001 -> default display.Context.SetDeviationCoefficient(0.0001) # 0.001 -> default # First spline spnts = [] spnts.append(gp_Pnt(-4, 0, 2)) spnts.append(gp_Pnt(-7, 2, 2)) spnts.append(gp_Pnt(-6, 3, 1)) spnts.append(gp_Pnt(-4, 3, -1)) spnts.append(gp_Pnt(-3, 5, -2)) spnts.append(gp_Pnt(-7, 1, -1)) spnts.append(gp_Pnt(-3, 3, 1)) spnts.append(gp_Pnt(-4, 3, -2)) spntsList = point_list_to_TColgp_Array1OfPnt(spnts) splineCurve = GeomAPI_PointsToBSpline(spntsList).Curve() bf = splineCurve.GetObject().FirstParameter(); bl = splineCurve.GetObject().LastParameter(); curveConv = GeomConvert_BSplineCurveToBezierCurve( splineCurve, 0.0, 1.0, 0.00001 ) print( "nbArcs: " + str( curveConv.NbArcs() ) + " f: " + str( bf ) + " l: " + str( bl ) ); for i in range( 1, curveConv.NbArcs() + 1, 1 ): arc = curveConv.Arc( i ) e = BRepBuilderAPI_MakeEdge( arc ) display.DisplayColoredShape( e.Edge(), 'GREEN' ) # try surface # 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) aBSplineSurface1 = aGeomFill1.Surface() display.DisplayShape(make_face(aBSplineSurface1, 1e-6)) surfaceConv = GeomConvert_BSplineSurfaceToBezierSurface( aBSplineSurface1 ) print( "nbPatches u: " + str( surfaceConv.NbUPatches() ) + " v: " + str( surfaceConv.NbVPatches() ) ); print( "nbArcs: " + str( curveConv.NbArcs() ) + " f: " + str( bf ) + " l: " + str( bl ) ); for i in range( 1, surfaceConv.NbUPatches() + 1, 1 ): for j in range( 1, surfaceConv.NbVPatches() + 1, 1 ): patch = surfaceConv.Patch( i, j ) display.DisplayColoredShape( patch, 'GREEN' ) if __name__ == '__main__': test() start_display()