44import vtk
55import numpy as np
66
7- # TODO: add the connectivity to the ffd control points to visualize the lattice.
8-
97def write_bounding_box (parameters , outfile , write_deformed = True ):
108 """
119 Method that writes a vtk file containing the FFD lattice. This method
@@ -31,52 +29,50 @@ def write_bounding_box(parameters, outfile, write_deformed=True):
3129 aux_x = np .linspace (0 , parameters .lenght_box_x , parameters .n_control_points [0 ])
3230 aux_y = np .linspace (0 , parameters .lenght_box_y , parameters .n_control_points [1 ])
3331 aux_z = np .linspace (0 , parameters .lenght_box_z , parameters .n_control_points [2 ])
34- lattice_y_coords , lattice_x_coords , lattice_z_coords = np .meshgrid (aux_y , aux_x , aux_z )
35-
36- if write_deformed :
37- box_points = np .array ([lattice_x_coords .ravel () + parameters .array_mu_x .ravel () * parameters .lenght_box_x ,\
38- lattice_y_coords .ravel () + parameters .array_mu_y .ravel () * parameters .lenght_box_y , \
39- lattice_z_coords .ravel () + parameters .array_mu_z .ravel () * parameters .lenght_box_z ])
40- else :
41- box_points = np .array ([lattice_x_coords .ravel (), lattice_y_coords .ravel (), \
42- lattice_z_coords .ravel ()])
43-
32+ lattice_z_coords , lattice_y_coords , lattice_x_coords = np .meshgrid (aux_z , aux_y , aux_x )
33+
34+ if write_deformed == False :
35+ box_points = np .array ([lattice_x_coords .ravel (), lattice_y_coords .ravel (), lattice_z_coords .ravel ()])
36+ if write_deformed == True :
37+ box_points = np .array ([lattice_x_coords .ravel () + parameters .array_mu_x .ravel ()* parameters .lenght_box_x , \
38+ lattice_y_coords .ravel () + parameters .array_mu_y .ravel ()* parameters .lenght_box_y , \
39+ lattice_z_coords .ravel () + parameters .array_mu_z .ravel ()* parameters .lenght_box_z ])
40+
4441 n_rows = box_points .shape [1 ]
45- box_points = np .dot (parameters .rotation_matrix , box_points ) + \
46- np .transpose (np .tile (parameters .origin_box , (n_rows , 1 )))
47-
48- _write_vtk_box (box_points , outfile )
49-
5042
51- def _write_vtk_box (box_points , filename ):
43+ box_points = np .dot (parameters .rotation_matrix ,box_points ) + np .transpose (np .tile (parameters .origin_box , (n_rows ,1 )))
44+
45+ _write_vtk_box (box_points , outfile , parameters .n_control_points )
46+
47+
48+ def _write_vtk_box (box_points , filename , dimensions ):
5249 """
53- Private method that writes a vtk file containing FFD control points.
54-
50+ Method that writes a vtk file containing FFD control points.
51+
5552 :param numpy.ndarray box_points: coordinates of the FFD control points.
5653 :param string filename: name of the output file.
54+ :param list dimensions: dimension of the lattice in (x, y, z) directions.
5755 """
5856 # setup points and vertices
5957 points = vtk .vtkPoints ()
60- vertices = vtk .vtkCellArray ()
61-
58+
6259 for index in range (0 , box_points .shape [1 ]):
63- ind = points .InsertNextPoint (box_points [0 , index ], box_points [1 , index ], box_points [2 , index ])
64- vertices .InsertNextCell (1 )
65- vertices .InsertCellPoint (ind )
66-
67- polydata = vtk .vtkPolyData ()
68- polydata .SetPoints (points )
69- polydata .SetVerts (vertices )
70- polydata .Modified ()
71-
72- writer = vtk .vtkDataSetWriter ()
60+ id = points .InsertNextPoint (box_points [0 , index ], box_points [1 , index ], box_points [2 , index ])
61+
62+ grid = vtk .vtkStructuredGrid ()
63+
64+ grid .SetPoints (points )
65+ grid .SetDimensions (dimensions )
66+ grid .Modified ()
67+
68+ writer = vtk .vtkStructuredGridWriter ()
7369 writer .SetFileName (filename )
74-
70+
7571 if vtk .VTK_MAJOR_VERSION <= 5 :
76- polydata .Update ()
77- writer .SetInput (polydata )
72+ grid .Update ()
73+ writer .SetInput (grid )
7874 else :
79- writer .SetInputData (polydata )
80-
75+ writer .SetInputData (grid )
76+
8177 writer .Write ()
8278
0 commit comments