@@ -96,11 +96,30 @@ class FFD(OriginalFFD):
9696 >>> import pygem.params as ffdp
9797 >>> import numpy as np
9898 >>> ffd = FFD()
99- >>> ffd.read_parameters('tests/test_datasets/test_pipe.iges')
99+ >>> ffd.read_parameters(
100+ >>> 'tests/test_datasets/parameters_test_ffd_iges.prm')
100101 >>> input_cad_file_name = "input.iges"
101102 >>> modified_cad_file_name = "output.iges"
102103 >>> ffd(input_cad_file_name,modified_cad_file_name)
103104 """
105+ def __init__ (self , n_control_points = None ):
106+ self .conversion_unit = 1.
107+
108+ self .box_length = np .array ([1. , 1. , 1. ])
109+ self .box_origin = np .array ([0. , 0. , 0. ])
110+ self .rot_angle = np .array ([0. , 0. , 0. ])
111+
112+ self .array_mu_x = None
113+ self .array_mu_y = None
114+ self .array_mu_z = None
115+
116+ if n_control_points is None :
117+ n_control_points = [2 , 2 , 2 ]
118+ self .n_control_points = n_control_points
119+ self .uKnotsToAdd = 30
120+ self .vKnotsToAdd = 30
121+ self .knotsToAdd = 30
122+ self .tolerance = 1e-4
104123
105124 def __call__ (self , obj , dst = None ):
106125 """
@@ -119,9 +138,6 @@ def __call__(self, obj, dst=None):
119138
120139 print ("Modifying faces" )
121140
122-
123-
124-
125141 #create compound to store modified faces
126142 compound_builder = BRep_Builder ()
127143 compound = TopoDS_Compound ()
@@ -137,7 +153,6 @@ def __call__(self, obj, dst=None):
137153 while faces_explorer .More ():
138154 # performing some conversions to get the right
139155 # format (BSplineSurface)
140- print ("Processing face " , faceCount )
141156 face = topods_Face (faces_explorer .Current ())
142157 nurbs_converter = BRepBuilderAPI_NurbsConvert (face )
143158 nurbs_face = nurbs_converter .Shape ()
@@ -149,29 +164,16 @@ def __call__(self, obj, dst=None):
149164 bspline_face = geomconvert_SurfaceToBSplineSurface (brep_face )
150165 # we will then add an amount of nodes that will grant
151166 # us our prescribed resolution both along u and v
152- uKnotsToAdd = 30
153- vKnotsToAdd = 30
154- print ("Added U knots: " , uKnotsToAdd )
155- print ("Added V knots: " , vKnotsToAdd )
156- for i in range (uKnotsToAdd ):
167+ for i in range (self .uKnotsToAdd ):
157168 bspline_face .InsertUKnot (bounds [0 ]+ \
158- i * (bounds [1 ]- bounds [0 ])/ uKnotsToAdd , 1 , 1e-7 )
159- for i in range (vKnotsToAdd ):
169+ i * (bounds [1 ]- bounds [0 ])/ self . uKnotsToAdd , 1 , self . tolerance )
170+ for i in range (self . vKnotsToAdd ):
160171 bspline_face .InsertVKnot (bounds [2 ]+ \
161- i * (bounds [3 ]- bounds [2 ])/ vKnotsToAdd , 1 , 1e-7 )
172+ i * (bounds [3 ]- bounds [2 ])/ self . vKnotsToAdd , 1 , self . tolerance )
162173
163174 # openCascade object
164175 occ_face = bspline_face
165176
166- bounds = 0.0
167- bounds = occ_face .Bounds ()
168- u_min = bounds [0 ]
169- u_max = bounds [1 ]
170- v_min = bounds [2 ]
171- v_max = bounds [3 ]
172- center = occ_face .Value ((u_min + u_max )/ 2.0 , (v_min + v_max )/ 2.0 )
173- print ("Face Center: " , center .X (), center .Y (), center .Z ())
174-
175177 # extract the Control Points of each face
176178 n_poles_u = occ_face .NbUPoles ()
177179 n_poles_v = occ_face .NbVPoles ()
@@ -212,8 +214,7 @@ def __call__(self, obj, dst=None):
212214 #later cut this new face with all the wires that the original
213215 # face had this tolerance can be moved among the function
214216 # parameters
215- tolerance = 1e-2
216- brep = BRepBuilderAPI_MakeFace (occ_face , tolerance ).Face ()
217+ brep = BRepBuilderAPI_MakeFace (occ_face , self .tolerance ).Face ()
217218
218219
219220 # we here start looping on the wires of the original face
@@ -230,7 +231,6 @@ def __call__(self, obj, dst=None):
230231 print ("Wire" , wire_count + 1 , "is outer wire" )
231232 wire_count += 1
232233 wire_explorer .Next ()
233- print ("This face has " , wire_count , " wires" )
234234
235235 #we now start really looping on the wires
236236 #we will create a single curve joining all the edges in the wire
@@ -259,7 +259,7 @@ def __call__(self, obj, dst=None):
259259 this_bspline_edge = \
260260 geomconvert_CurveToBSplineCurve (h_geom_edge )
261261 bspline_geom_edge = this_bspline_edge
262- h_bspline_edge .Add (this_bspline_edge , tolerance )
262+ h_bspline_edge .Add (this_bspline_edge , self . tolerance )
263263 edgesCount += 1
264264
265265 edge_explorer .Next ()
@@ -269,12 +269,12 @@ def __call__(self, obj, dst=None):
269269
270270 # number of knots is enriched here: this can become a user
271271 # prescribed parameter for the class
272- knotsToAdd = 30
273272 firstParam = bspline_geom_edge .FirstParameter ()
274273 lastParam = bspline_geom_edge .LastParameter ()
275- for i in range (knotsToAdd ):
274+ for i in range (self . knotsToAdd ):
276275 bspline_geom_edge .InsertKnot (firstParam + \
277- i * (lastParam - firstParam )/ knotsToAdd , 1 , 1e-7 )
276+ i * (lastParam - firstParam )/ self .knotsToAdd , 1 , \
277+ self .tolerance )
278278 shapesList = TopTools_ListOfShape ()
279279 # openCascade object
280280 occ_edge = bspline_geom_edge
@@ -314,10 +314,6 @@ def __call__(self, obj, dst=None):
314314 wire_maker = BRepBuilderAPI_MakeWire ()
315315 wire_maker .Add (shapesList )
316316 result_wire = wire_maker .Wire ()
317- iges_handler = IgesHandler ()
318- iges_handler .write_shape_to_file (result_wire , "face_" + \
319- str (faceCount )+ "_wire_" + \
320- str (wire_count )+ ".iges" )
321317
322318 # now, the wire can be outer or inner. we store the outer
323319 # and (possible) inner ones in different lists
0 commit comments