Skip to content

Commit 325c783

Browse files
committed
Merge pull request #73 from fsalmoir/connectivity
connectivity for the bounding box added
2 parents cae5afc + b330ef2 commit 325c783

File tree

5 files changed

+48
-102
lines changed

5 files changed

+48
-102
lines changed

pygem/utils.py

Lines changed: 24 additions & 26 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,7 +29,7 @@ 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)
32+
lattice_z_coords, lattice_y_coords, lattice_x_coords = np.meshgrid(aux_z, aux_y, aux_x)
3533

3634
if write_deformed:
3735
box_points = np.array([lattice_x_coords.ravel() + parameters.array_mu_x.ravel() * parameters.lenght_box_x,\
@@ -40,43 +38,43 @@ def write_bounding_box(parameters, outfile, write_deformed=True):
4038
else:
4139
box_points = np.array([lattice_x_coords.ravel(), lattice_y_coords.ravel(), \
4240
lattice_z_coords.ravel()])
43-
41+
4442
n_rows = box_points.shape[1]
43+
4544
box_points = np.dot(parameters.rotation_matrix, box_points) + \
4645
np.transpose(np.tile(parameters.origin_box, (n_rows, 1)))
47-
48-
_write_vtk_box(box_points, outfile)
49-
50-
51-
def _write_vtk_box(box_points, filename):
46+
47+
_write_vtk_box(box_points, outfile, parameters.n_control_points)
48+
49+
50+
def _write_vtk_box(box_points, filename, dimensions):
5251
"""
5352
Private method that writes a vtk file containing FFD control points.
54-
53+
5554
:param numpy.ndarray box_points: coordinates of the FFD control points.
5655
:param string filename: name of the output file.
56+
:param list dimensions: dimension of the lattice in (x, y, z) directions.
5757
"""
5858
# setup points and vertices
5959
points = vtk.vtkPoints()
60-
vertices = vtk.vtkCellArray()
61-
60+
6261
for index in range(0, box_points.shape[1]):
6362
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()
63+
64+
grid = vtk.vtkStructuredGrid()
65+
66+
grid.SetPoints(points)
67+
grid.SetDimensions(dimensions)
68+
grid.Modified()
69+
70+
writer = vtk.vtkStructuredGridWriter()
7371
writer.SetFileName(filename)
74-
72+
7573
if vtk.VTK_MAJOR_VERSION <= 5:
76-
polydata.Update()
77-
writer.SetInput(polydata)
74+
grid.Update()
75+
writer.SetInput(grid)
7876
else:
79-
writer.SetInputData(polydata)
80-
77+
writer.SetInputData(grid)
78+
8179
writer.Write()
8280

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: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
11
# vtk DataFile Version 4.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: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
11
# vtk DataFile Version 4.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)