1+ """
2+ Module for the blade bottom-up parametrized construction.
3+ """
4+ import numpy as np
5+ import matplotlib .pyplot as plt
6+ from mpl_toolkits .mplot3d import Axes3D
7+ from OCC .Core .BRepOffsetAPI import BRepOffsetAPI_ThruSections
8+ from OCC .Core .gp import gp_Pnt
9+ from OCC .Core .TColgp import TColgp_HArray1OfPnt
10+ from OCC .Core .GeomAPI import GeomAPI_Interpolate
11+ from OCC .Core .BRepBuilderAPI import BRepBuilderAPI_MakeVertex ,\
12+ BRepBuilderAPI_MakeEdge , BRepBuilderAPI_MakeWire ,\
13+ BRepBuilderAPI_Sewing , BRepBuilderAPI_MakeSolid
14+
15+ class InterpolatedFace :
16+
17+ def __init__ (self , pts , max_deg = 3 , tolerance = 1e-10 ):
18+
19+ print (pts .shape )
20+ if pts .ndim not in [2 , 3 ]:
21+ raise ValueError ("pts must be a 2D or 3D array." )
22+
23+ if pts .ndim == 2 :
24+ pts = pts [None , :, :]
25+
26+ if pts .shape [1 ] != 3 :
27+ raise ValueError ("Each point must have 3 coordinates for X, Y, Z." )
28+
29+ self .max_deg = max_deg
30+ self .tolerance = tolerance
31+
32+ generator = BRepOffsetAPI_ThruSections (False , False , tolerance )
33+ generator .SetMaxDegree (max_deg )
34+
35+ for id_section , section in enumerate (pts ):
36+ vertices = TColgp_HArray1OfPnt (1 , section .shape [1 ])
37+ for id_pt , pt in enumerate (section .T , start = 1 ):
38+ vertices .SetValue (id_pt , gp_Pnt (* pt ))
39+
40+ # Initializes an algorithm for constructing a constrained
41+ # BSpline curve passing through the points of the blade last
42+ # section
43+ bspline = GeomAPI_Interpolate (vertices , False , tolerance )
44+ bspline .Perform ()
45+
46+ edge = BRepBuilderAPI_MakeEdge (bspline .Curve ()).Edge ()
47+
48+ if id_section == 0 :
49+ root_edge = edge
50+
51+ # Add BSpline wire to the generator constructor
52+ generator .AddWire (BRepBuilderAPI_MakeWire (edge ).Wire ())
53+
54+ generator .Build ()
55+ self .face = generator .GeneratedFace (root_edge )
0 commit comments