33"""
44import vtk
55import numpy as np
6+ import matplotlib .pyplot as plt
7+
68
79def write_bounding_box (parameters , outfile , write_deformed = True ):
810 """
@@ -32,29 +34,30 @@ def write_bounding_box(parameters, outfile, write_deformed=True):
3234 lattice_y_coords , lattice_x_coords , lattice_z_coords = np .meshgrid (aux_y , aux_x , aux_z )
3335
3436 if write_deformed :
35- box_points = np .array ([lattice_x_coords .ravel () + parameters .array_mu_x .ravel () * parameters .lenght_box_x ,\
37+ box_points = np .array ([ \
38+ lattice_x_coords .ravel () + parameters .array_mu_x .ravel () * parameters .lenght_box_x , \
3639 lattice_y_coords .ravel () + parameters .array_mu_y .ravel () * parameters .lenght_box_y , \
3740 lattice_z_coords .ravel () + parameters .array_mu_z .ravel () * parameters .lenght_box_z ])
3841 else :
3942 box_points = np .array ([lattice_x_coords .ravel (), lattice_y_coords .ravel (), \
4043 lattice_z_coords .ravel ()])
41-
44+
4245 n_rows = box_points .shape [1 ]
4346
4447 box_points = np .dot (parameters .rotation_matrix , box_points ) + \
4548 np .transpose (np .tile (parameters .origin_box , (n_rows , 1 )))
46-
49+
4750 # step necessary to set the correct order to the box points for vtkStructuredGrid:
4851 # Data in vtkStructuredGrid are ordered with x increasing fastest, then y, then z
4952 dims = lattice_y_coords .shape
50- aux_xx = box_points [0 ,:].reshape (dims ).ravel (order = 'f' )
51- aux_yy = box_points [1 ,:].reshape (dims ).ravel (order = 'f' )
52- aux_zz = box_points [2 ,:].reshape (dims ).ravel (order = 'f' )
53+ aux_xx = box_points [0 , :].reshape (dims ).ravel (order = 'f' )
54+ aux_yy = box_points [1 , :].reshape (dims ).ravel (order = 'f' )
55+ aux_zz = box_points [2 , :].reshape (dims ).ravel (order = 'f' )
5356 reordered_box_points = np .array ((aux_xx , aux_yy , aux_zz ))
5457
5558 _write_vtk_box (reordered_box_points , outfile , parameters .n_control_points )
56-
57-
59+
60+
5861def _write_vtk_box (box_points , filename , dimensions ):
5962 """
6063 Private method that writes a vtk file containing FFD control points.
@@ -91,3 +94,40 @@ def _write_vtk_box(box_points, filename, dimensions):
9194
9295 writer .Write ()
9396
97+
98+ def plot_rbf_control_points (parameters , save_fig = False ):
99+ """
100+ Method to plot the control points of a RBFParameters class. It is possible to save the
101+ resulting figure.
102+
103+ :param bool save_fig: a flag to save the figure in png or not. If True the
104+ plot is not shown and the figure is saved with the name 'RBF_control_points.png'.
105+ The default value is False.
106+ """
107+ fig = plt .figure (1 )
108+ axes = fig .add_subplot (111 , projection = '3d' )
109+ orig = axes .scatter (parameters .original_control_points [:, 0 ], \
110+ parameters .original_control_points [:, 1 ], \
111+ parameters .original_control_points [:, 2 ], c = 'blue' , marker = 'o' )
112+ defor = axes .scatter (parameters .deformed_control_points [:, 0 ], \
113+ parameters .deformed_control_points [:, 1 ], \
114+ parameters .deformed_control_points [:, 2 ], c = 'red' , marker = 'x' )
115+
116+ axes .set_xlabel ('X axis' )
117+ axes .set_ylabel ('Y axis' )
118+ axes .set_zlabel ('Z axis' )
119+
120+ plt .legend ((orig , defor ), \
121+ ('Original' , 'Deformed' ), \
122+ scatterpoints = 1 , \
123+ loc = 'lower left' , \
124+ ncol = 2 , \
125+ fontsize = 10 )
126+
127+ # Show the plot to the screen
128+ if not save_fig :
129+ plt .show ()
130+ else :
131+ fig .savefig ('RBF_control_points.png' )
132+
133+
0 commit comments