forked from tpaviot/pythonocc-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore_geometry_bspline.py
More file actions
76 lines (63 loc) · 2.66 KB
/
Copy pathcore_geometry_bspline.py
File metadata and controls
76 lines (63 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python
##Copyright 2009-2014 Jelle Ferina (jelleferinga@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 <http://www.gnu.org/licenses/>.
from __future__ import print_function
from OCC.gp import gp_Pnt2d
from OCC.Geom2dAPI import Geom2dAPI_Interpolate, Geom2dAPI_PointsToBSpline
from OCC.TColgp import TColgp_HArray1OfPnt2d, TColgp_Array1OfPnt2d
from OCC.Display.SimpleGui import init_display
display, start_display, add_menu, add_function_to_menu = init_display()
def bspline():
# the first bspline
array = TColgp_Array1OfPnt2d(1, 5)
array.SetValue(1, gp_Pnt2d(0, 0))
array.SetValue(2, gp_Pnt2d(1, 2))
array.SetValue(3, gp_Pnt2d(2, 3))
array.SetValue(4, gp_Pnt2d(4, 3))
array.SetValue(5, gp_Pnt2d(5, 5))
bspline_1 = Geom2dAPI_PointsToBSpline(array).Curve()
# the second one
harray = TColgp_HArray1OfPnt2d(1, 5)
harray.SetValue(1, gp_Pnt2d(0, 0))
harray.SetValue(2, gp_Pnt2d(1, 2))
harray.SetValue(3, gp_Pnt2d(2, 3))
harray.SetValue(4, gp_Pnt2d(4, 3))
harray.SetValue(5, gp_Pnt2d(5, 5))
anInterpolation = Geom2dAPI_Interpolate(harray.GetHandle(), False, 0.01)
anInterpolation.Perform()
bspline_2 = anInterpolation.Curve()
harray2 = TColgp_HArray1OfPnt2d(1, 5)
harray2.SetValue(1, gp_Pnt2d(11, 0))
harray2.SetValue(2, gp_Pnt2d(12, 2))
harray2.SetValue(3, gp_Pnt2d(13, 3))
harray2.SetValue(4, gp_Pnt2d(15, 3))
harray2.SetValue(5, gp_Pnt2d(16, 5))
anInterpolation2 = Geom2dAPI_Interpolate(harray.GetHandle(), True, 0.01)
anInterpolation2.Perform()
bspline_3 = anInterpolation2.Curve()
for j in range(array.Lower(), array.Upper()+1):
p = array.Value(j)
display.DisplayShape(p, update=False)
for j in range(harray.Lower(), harray.Upper()+1):
p = harray.Value(j)
display.DisplayShape(p, update=False)
display.DisplayShape(bspline_1, update=False)
display.DisplayShape(bspline_2, update=False, color='GREEN')
display.DisplayShape(bspline_3, update=True, color='BLUE')
if __name__ == '__main__':
bspline()
start_display()