|
1 | 1 | """ |
2 | | -Utilities for reading and writing parameters files to perform the desired |
| 2 | +Utilities for reading and writing parameters files to perform FFD |
3 | 3 | geometrical morphing. |
4 | 4 | """ |
5 | 5 | try: |
6 | 6 | import configparser as configparser |
7 | 7 | except ImportError: |
8 | 8 | import ConfigParser as configparser |
9 | 9 | import os |
10 | | - |
11 | 10 | import numpy as np |
| 11 | +from OCC.Bnd import Bnd_Box |
12 | 12 | from OCC.BRepBndLib import brepbndlib_Add |
13 | 13 | from OCC.BRepMesh import BRepMesh_IncrementalMesh |
14 | | -from OCC.Bnd import Bnd_Box |
15 | | - |
16 | 14 | import vtk |
17 | 15 | import pygem.affine as at |
18 | | -from math import radians |
19 | 16 |
|
20 | 17 |
|
21 | 18 | class FFDParameters(object): |
@@ -44,7 +41,7 @@ class FFDParameters(object): |
44 | 41 | :Example: from file |
45 | 42 |
|
46 | 43 | >>> import pygem.params as ffdp |
47 | | - >>> |
| 44 | + >>> |
48 | 45 | >>> # Reading an existing file |
49 | 46 | >>> params1 = ffdp.FFDParameters() |
50 | 47 | >>> params1.read_parameters( |
@@ -115,8 +112,8 @@ def rotation_matrix(self): |
115 | 112 | :rtype: numpy.ndarray |
116 | 113 | """ |
117 | 114 | return at.angles2matrix( |
118 | | - radians(self.rot_angle[2]), radians(self.rot_angle[1]), |
119 | | - radians(self.rot_angle[0])) |
| 115 | + np.radians(self.rot_angle[2]), np.radians(self.rot_angle[1]), |
| 116 | + np.radians(self.rot_angle[0])) |
120 | 117 |
|
121 | 118 | @property |
122 | 119 | def position_vertices(self): |
@@ -213,69 +210,99 @@ def write_parameters(self, filename='parameters.prm'): |
213 | 210 | output_string += 'n control points z: ' + str( |
214 | 211 | self.n_control_points[2]) + '\n' |
215 | 212 |
|
216 | | - output_string += '\n# box lenght indicates the length of the FFD bounding box along the three canonical directions (x, y, z).\n' |
| 213 | + output_string += '\n# box lenght indicates the length of the FFD ' |
| 214 | + output_string += 'bounding box along the three canonical directions (x, y, z).\n' |
| 215 | + |
217 | 216 | output_string += '# It uses the local coordinate system.\n' |
218 | | - output_string += '# For example to create a 2 x 1.5 x 3 meters box use the following: lenght box: 2.0, 1.5, 3.0\n' |
| 217 | + output_string += '# For example to create a 2 x 1.5 x 3 meters box ' |
| 218 | + output_string += 'use the following: lenght box: 2.0, 1.5, 3.0\n' |
| 219 | + |
219 | 220 | output_string += 'box lenght x: ' + str(self.lenght_box[0]) + '\n' |
220 | 221 | output_string += 'box lenght y: ' + str(self.lenght_box[1]) + '\n' |
221 | 222 | output_string += 'box lenght z: ' + str(self.lenght_box[2]) + '\n' |
222 | 223 |
|
223 | | - output_string += '\n# box origin indicates the x, y, and z coordinates of the origin of the FFD bounding box. That is center of\n' |
224 | | - output_string += '# rotation of the bounding box. It corresponds to the point coordinates with position [0][0][0].\n' |
| 224 | + output_string += '\n# box origin indicates the x, y, and z coordinates of ' |
| 225 | + output_string += 'the origin of the FFD bounding box. That is center of\n' |
| 226 | + |
| 227 | + output_string += '# rotation of the bounding box. It corresponds to ' |
| 228 | + output_string += 'the point coordinates with position [0][0][0].\n' |
| 229 | + |
225 | 230 | output_string += '# See section "Parameters weights" for more details.\n' |
226 | | - output_string += '# For example, if the origin is equal to 0., 0., 0., use the following: origin box: 0., 0., 0.\n' |
| 231 | + output_string += '# For example, if the origin is equal to 0., 0., 0., use ' |
| 232 | + output_string += 'the following: origin box: 0., 0., 0.\n' |
| 233 | + |
227 | 234 | output_string += 'box origin x: ' + str(self.origin_box[0]) + '\n' |
228 | 235 | output_string += 'box origin y: ' + str(self.origin_box[1]) + '\n' |
229 | 236 | output_string += 'box origin z: ' + str(self.origin_box[2]) + '\n' |
230 | 237 |
|
231 | | - output_string += '\n# rotation angle indicates the rotation angle around the x, y, and z axis of the FFD bounding box in degrees.\n' |
| 238 | + output_string += '\n# rotation angle indicates the rotation angle ' |
| 239 | + output_string += 'around the x, y, and z axis of the FFD bounding box in degrees.\n' |
| 240 | + |
232 | 241 | output_string += '# The rotation is done with respect to the box origin.\n' |
233 | | - output_string += '# For example, to rotate the box by 2 deg along the z direction, use the following: rotation angle: 0., 0., 2.\n' |
| 242 | + output_string += '# For example, to rotate the box by 2 deg along the z ' |
| 243 | + output_string += 'direction, use the following: rotation angle: 0., 0., 2.\n' |
| 244 | + |
234 | 245 | output_string += 'rotation angle x: ' + str(self.rot_angle[0]) + '\n' |
235 | 246 | output_string += 'rotation angle y: ' + str(self.rot_angle[1]) + '\n' |
236 | 247 | output_string += 'rotation angle z: ' + str(self.rot_angle[2]) + '\n' |
237 | 248 |
|
238 | 249 | output_string += '\n\n[Parameters weights]\n' |
239 | | - output_string += '# This section describes the weights of the FFD control points.\n' |
| 250 | + output_string += '# This section describes the weights of the FFD ' |
| 251 | + output_string += 'control points.\n' |
| 252 | + |
240 | 253 | output_string += '# We adopt the following convention:\n' |
241 | | - output_string += '# For example with a 2x2x2 grid of control points we have to fill a 2x2x2 matrix of weights.\n' |
242 | | - output_string += '# If a weight is equal to zero you can discard the line since the default is zero.\n' |
| 254 | + output_string += '# For example with a 2x2x2 grid of control points we ' |
| 255 | + output_string += 'have to fill a 2x2x2 matrix of weights.\n' |
| 256 | + |
| 257 | + output_string += '# If a weight is equal to zero you can discard the line ' |
| 258 | + output_string += 'since the default is zero.\n' |
| 259 | + |
243 | 260 | output_string += '#\n' |
244 | 261 | output_string += '# | x index | y index | z index | weight |\n' |
245 | 262 | output_string += '# --------------------------------------\n' |
246 | 263 | output_string += '# | 0 | 0 | 0 | 1.0 |\n' |
247 | | - output_string += '# | 0 | 1 | 1 | 0.0 | --> you can erase this line without effects\n' |
| 264 | + output_string += '# | 0 | 1 | 1 | 0.0 | --> you ' |
| 265 | + output_string += 'can erase this line without effects\n' |
248 | 266 | output_string += '# | 0 | 1 | 0 | -2.1 |\n' |
249 | 267 | output_string += '# | 0 | 0 | 1 | 3.4 |\n' |
250 | 268 |
|
251 | | - output_string += '\n# parameter x collects the displacements along x, normalized with the box lenght x.' |
| 269 | + output_string += '\n# parameter x collects the displacements along x, ' |
| 270 | + output_string += 'normalized with the box lenght x.' |
| 271 | + |
252 | 272 | output_string += '\nparameter x:' |
253 | 273 | offset = 1 |
254 | 274 | for i in range(0, self.n_control_points[0]): |
255 | 275 | for j in range(0, self.n_control_points[1]): |
256 | 276 | for k in range(0, self.n_control_points[2]): |
257 | | - output_string += offset * ' ' + str(i) + ' ' + str(j) + ' ' + str(k) + \ |
258 | | - ' ' + str(self.array_mu_x[i][j][k]) + '\n' |
| 277 | + output_string += offset * ' ' + str(i) + ' ' + str( |
| 278 | + j) + ' ' + str(k) + ' ' + str( |
| 279 | + self.array_mu_x[i][j][k]) + '\n' |
259 | 280 | offset = 13 |
260 | 281 |
|
261 | | - output_string += '\n# parameter y collects the displacements along y, normalized with the box lenght y.' |
| 282 | + output_string += '\n# parameter y collects the displacements along y, ' |
| 283 | + output_string += 'normalized with the box lenght y.' |
| 284 | + |
262 | 285 | output_string += '\nparameter y:' |
263 | 286 | offset = 1 |
264 | 287 | for i in range(0, self.n_control_points[0]): |
265 | 288 | for j in range(0, self.n_control_points[1]): |
266 | 289 | for k in range(0, self.n_control_points[2]): |
267 | | - output_string += offset * ' ' + str(i) + ' ' + str(j) + ' ' + str(k) + \ |
268 | | - ' ' + str(self.array_mu_y[i][j][k]) + '\n' |
| 290 | + output_string += offset * ' ' + str(i) + ' ' + str( |
| 291 | + j) + ' ' + str(k) + ' ' + str( |
| 292 | + self.array_mu_y[i][j][k]) + '\n' |
269 | 293 | offset = 13 |
270 | 294 |
|
271 | | - output_string += '\n# parameter z collects the displacements along z, normalized with the box lenght z.' |
| 295 | + output_string += '\n# parameter z collects the displacements along z, ' |
| 296 | + output_string += 'normalized with the box lenght z.' |
| 297 | + |
272 | 298 | output_string += '\nparameter z:' |
273 | 299 | offset = 1 |
274 | 300 | for i in range(0, self.n_control_points[0]): |
275 | 301 | for j in range(0, self.n_control_points[1]): |
276 | 302 | for k in range(0, self.n_control_points[2]): |
277 | | - output_string += offset * ' ' + str(i) + ' ' + str(j) + ' ' + str(k) + \ |
278 | | - ' ' + str(self.array_mu_z[i][j][k]) + '\n' |
| 303 | + output_string += offset * ' ' + str(i) + ' ' + str( |
| 304 | + j) + ' ' + str(k) + ' ' + str( |
| 305 | + self.array_mu_z[i][j][k]) + '\n' |
279 | 306 | offset = 13 |
280 | 307 |
|
281 | 308 | with open(filename, 'w') as f: |
|
0 commit comments