Skip to content

Commit 5534c07

Browse files
fsalmoirmtezzele
authored andcommitted
connectivity for the bounding box added
1 parent 66507d6 commit 5534c07

File tree

5 files changed

+59
-115
lines changed

5 files changed

+59
-115
lines changed

pygem/utils.py

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import vtk
55
import numpy as np
66

7-
# TODO: add the connectivity to the ffd control points to visualize the lattice.
8-
97
def 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

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
11
# vtk DataFile Version 3.0
22
vtk output
33
ASCII
4-
DATASET POLYDATA
4+
DATASET STRUCTURED_GRID
5+
DIMENSIONS 3 2 2
56
POINTS 12 float
6-
-20 -55 -45 -4.37166 -55 43.6327 -42.9398 31.9333 -40.9551
7-
-27.3115 31.9333 47.6776 1.40315 -49.1766 -48.774 17.0315 -49.1766 39.8587
8-
-21.5367 37.7568 -44.729 -5.90834 37.7568 43.9037 52.8929 -77.5023 -149.241
9-
38.4346 -43.3531 36.0848 -0.133524 43.5802 -48.503 15.4948 43.5802 40.1297
10-
11-
VERTICES 12 24
12-
1 0
13-
1 1
14-
1 2
15-
1 3
16-
1 4
17-
1 5
18-
1 6
19-
1 7
20-
1 8
21-
1 9
22-
1 10
23-
1 11
7+
-20 -55 -45 1.40315 -49.1766 -48.774 22.8063 -43.3531 -52.5479
8+
-4.37166 -55 43.6327 17.0315 -49.1766 39.8587 38.4346 -43.3531 36.0848
9+
-42.9398 31.9333 -40.9551 -21.5367 37.7568 -44.729 29.9531 9.431 -145.196
10+
-27.3115 31.9333 47.6776 -5.90834 37.7568 43.9037 15.4948 43.5802 40.1297
2411

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
1-
# vtk DataFile Version 4.0
1+
# vtk DataFile Version 3.0
22
vtk output
33
ASCII
4-
DATASET POLYDATA
4+
DATASET STRUCTURED_GRID
5+
DIMENSIONS 3 2 2
56
POINTS 12 float
6-
-20 -55 -45 -4.37166 -55 43.6327 -42.9398 31.9333 -40.9551
7-
-27.3115 31.9333 47.6776 1.40315 -49.1766 -48.774 17.0315 -49.1766 39.8587
8-
-21.5367 37.7568 -44.729 -5.90834 37.7568 43.9037 52.8929 -77.5023 -149.241
9-
38.4346 -43.3531 36.0848 -0.133524 43.5802 -48.503 15.4948 43.5802 40.1297
10-
11-
VERTICES 12 24
12-
1 0
13-
1 1
14-
1 2
15-
1 3
16-
1 4
17-
1 5
18-
1 6
19-
1 7
20-
1 8
21-
1 9
22-
1 10
23-
1 11
7+
-20 -55 -45 1.40315 -49.1766 -48.774 22.8063 -43.3531 -52.5479
8+
-4.37166 -55 43.6327 17.0315 -49.1766 39.8587 38.4346 -43.3531 36.0848
9+
-42.9398 31.9333 -40.9551 -21.5367 37.7568 -44.729 29.9531 9.431 -145.196
10+
-27.3115 31.9333 47.6776 -5.90834 37.7568 43.9037 15.4948 43.5802 40.1297
2411

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
11
# vtk DataFile Version 3.0
22
vtk output
33
ASCII
4-
DATASET POLYDATA
4+
DATASET STRUCTURED_GRID
5+
DIMENSIONS 3 2 2
56
POINTS 12 float
6-
-20 -55 -45 -4.37166 -55 43.6327 -42.9398 31.9333 -40.9551
7-
-27.3115 31.9333 47.6776 1.40315 -49.1766 -48.774 17.0315 -49.1766 39.8587
8-
-21.5367 37.7568 -44.729 -5.90834 37.7568 43.9037 22.8063 -43.3531 -52.5479
9-
38.4346 -43.3531 36.0848 -0.133524 43.5802 -48.503 15.4948 43.5802 40.1297
10-
11-
VERTICES 12 24
12-
1 0
13-
1 1
14-
1 2
15-
1 3
16-
1 4
17-
1 5
18-
1 6
19-
1 7
20-
1 8
21-
1 9
22-
1 10
23-
1 11
7+
-20 -55 -45 1.40315 -49.1766 -48.774 22.8063 -43.3531 -52.5479
8+
-4.37166 -55 43.6327 17.0315 -49.1766 39.8587 38.4346 -43.3531 36.0848
9+
-42.9398 31.9333 -40.9551 -21.5367 37.7568 -44.729 -0.133524 43.5802 -48.503
10+
-27.3115 31.9333 47.6776 -5.90834 37.7568 43.9037 15.4948 43.5802 40.1297
2411

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
1-
# vtk DataFile Version 4.0
1+
# vtk DataFile Version 3.0
22
vtk output
33
ASCII
4-
DATASET POLYDATA
4+
DATASET STRUCTURED_GRID
5+
DIMENSIONS 3 2 2
56
POINTS 12 float
6-
-20 -55 -45 -4.37166 -55 43.6327 -42.9398 31.9333 -40.9551
7-
-27.3115 31.9333 47.6776 1.40315 -49.1766 -48.774 17.0315 -49.1766 39.8587
8-
-21.5367 37.7568 -44.729 -5.90834 37.7568 43.9037 22.8063 -43.3531 -52.5479
9-
38.4346 -43.3531 36.0848 -0.133524 43.5802 -48.503 15.4948 43.5802 40.1297
10-
11-
VERTICES 12 24
12-
1 0
13-
1 1
14-
1 2
15-
1 3
16-
1 4
17-
1 5
18-
1 6
19-
1 7
20-
1 8
21-
1 9
22-
1 10
23-
1 11
7+
-20 -55 -45 1.40315 -49.1766 -48.774 22.8063 -43.3531 -52.5479
8+
-4.37166 -55 43.6327 17.0315 -49.1766 39.8587 38.4346 -43.3531 36.0848
9+
-42.9398 31.9333 -40.9551 -21.5367 37.7568 -44.729 -0.133524 43.5802 -48.503
10+
-27.3115 31.9333 47.6776 -5.90834 37.7568 43.9037 15.4948 43.5802 40.1297
2411

0 commit comments

Comments
 (0)