Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 24 additions & 26 deletions pygem/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import vtk
import numpy as np

# TODO: add the connectivity to the ffd control points to visualize the lattice.

def write_bounding_box(parameters, outfile, write_deformed=True):
"""
Method that writes a vtk file containing the FFD lattice. This method
Expand All @@ -31,7 +29,7 @@ def write_bounding_box(parameters, outfile, write_deformed=True):
aux_x = np.linspace(0, parameters.lenght_box_x, parameters.n_control_points[0])
aux_y = np.linspace(0, parameters.lenght_box_y, parameters.n_control_points[1])
aux_z = np.linspace(0, parameters.lenght_box_z, parameters.n_control_points[2])
lattice_y_coords, lattice_x_coords, lattice_z_coords = np.meshgrid(aux_y, aux_x, aux_z)
lattice_z_coords, lattice_y_coords, lattice_x_coords = np.meshgrid(aux_z, aux_y, aux_x)

if write_deformed:
box_points = np.array([lattice_x_coords.ravel() + parameters.array_mu_x.ravel() * parameters.lenght_box_x,\
Expand All @@ -40,43 +38,43 @@ def write_bounding_box(parameters, outfile, write_deformed=True):
else:
box_points = np.array([lattice_x_coords.ravel(), lattice_y_coords.ravel(), \
lattice_z_coords.ravel()])

n_rows = box_points.shape[1]

box_points = np.dot(parameters.rotation_matrix, box_points) + \
np.transpose(np.tile(parameters.origin_box, (n_rows, 1)))

_write_vtk_box(box_points, outfile)


def _write_vtk_box(box_points, filename):
_write_vtk_box(box_points, outfile, parameters.n_control_points)
def _write_vtk_box(box_points, filename, dimensions):
"""
Private method that writes a vtk file containing FFD control points.

:param numpy.ndarray box_points: coordinates of the FFD control points.
:param string filename: name of the output file.
:param list dimensions: dimension of the lattice in (x, y, z) directions.
"""
# setup points and vertices
points = vtk.vtkPoints()
vertices = vtk.vtkCellArray()


for index in range(0, box_points.shape[1]):
ind = points.InsertNextPoint(box_points[0, index], box_points[1, index], box_points[2, index])
vertices.InsertNextCell(1)
vertices.InsertCellPoint(ind)

polydata = vtk.vtkPolyData()
polydata.SetPoints(points)
polydata.SetVerts(vertices)
polydata.Modified()

writer = vtk.vtkDataSetWriter()

grid = vtk.vtkStructuredGrid()

grid.SetPoints(points)
grid.SetDimensions(dimensions)
grid.Modified()

writer = vtk.vtkStructuredGridWriter()
writer.SetFileName(filename)

if vtk.VTK_MAJOR_VERSION <= 5:
polydata.Update()
writer.SetInput(polydata)
grid.Update()
writer.SetInput(grid)
else:
writer.SetInputData(polydata)

writer.SetInputData(grid)
writer.Write()

25 changes: 6 additions & 19 deletions tests/test_datasets/box_modified_test_sphere_true_version5.vtk
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
# vtk DataFile Version 3.0
vtk output
ASCII
DATASET POLYDATA
DATASET STRUCTURED_GRID
DIMENSIONS 3 2 2
POINTS 12 float
-20 -55 -45 -4.37166 -55 43.6327 -42.9398 31.9333 -40.9551
-27.3115 31.9333 47.6776 1.40315 -49.1766 -48.774 17.0315 -49.1766 39.8587
-21.5367 37.7568 -44.729 -5.90834 37.7568 43.9037 52.8929 -77.5023 -149.241
38.4346 -43.3531 36.0848 -0.133524 43.5802 -48.503 15.4948 43.5802 40.1297

VERTICES 12 24
1 0
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
-20 -55 -45 1.40315 -49.1766 -48.774 22.8063 -43.3531 -52.5479
-4.37166 -55 43.6327 17.0315 -49.1766 39.8587 38.4346 -43.3531 36.0848
-42.9398 31.9333 -40.9551 -21.5367 37.7568 -44.729 29.9531 9.431 -145.196
-27.3115 31.9333 47.6776 -5.90834 37.7568 43.9037 15.4948 43.5802 40.1297

25 changes: 6 additions & 19 deletions tests/test_datasets/box_modified_test_sphere_true_version6.vtk
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
# vtk DataFile Version 4.0
vtk output
ASCII
DATASET POLYDATA
DATASET STRUCTURED_GRID
DIMENSIONS 3 2 2
POINTS 12 float
-20 -55 -45 -4.37166 -55 43.6327 -42.9398 31.9333 -40.9551
-27.3115 31.9333 47.6776 1.40315 -49.1766 -48.774 17.0315 -49.1766 39.8587
-21.5367 37.7568 -44.729 -5.90834 37.7568 43.9037 52.8929 -77.5023 -149.241
38.4346 -43.3531 36.0848 -0.133524 43.5802 -48.503 15.4948 43.5802 40.1297

VERTICES 12 24
1 0
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
-20 -55 -45 1.40315 -49.1766 -48.774 22.8063 -43.3531 -52.5479
-4.37166 -55 43.6327 17.0315 -49.1766 39.8587 38.4346 -43.3531 36.0848
-42.9398 31.9333 -40.9551 -21.5367 37.7568 -44.729 29.9531 9.431 -145.196
-27.3115 31.9333 47.6776 -5.90834 37.7568 43.9037 15.4948 43.5802 40.1297

25 changes: 6 additions & 19 deletions tests/test_datasets/box_test_sphere_true_version5.vtk
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
# vtk DataFile Version 3.0
vtk output
ASCII
DATASET POLYDATA
DATASET STRUCTURED_GRID
DIMENSIONS 3 2 2
POINTS 12 float
-20 -55 -45 -4.37166 -55 43.6327 -42.9398 31.9333 -40.9551
-27.3115 31.9333 47.6776 1.40315 -49.1766 -48.774 17.0315 -49.1766 39.8587
-21.5367 37.7568 -44.729 -5.90834 37.7568 43.9037 22.8063 -43.3531 -52.5479
38.4346 -43.3531 36.0848 -0.133524 43.5802 -48.503 15.4948 43.5802 40.1297

VERTICES 12 24
1 0
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
-20 -55 -45 1.40315 -49.1766 -48.774 22.8063 -43.3531 -52.5479
-4.37166 -55 43.6327 17.0315 -49.1766 39.8587 38.4346 -43.3531 36.0848
-42.9398 31.9333 -40.9551 -21.5367 37.7568 -44.729 -0.133524 43.5802 -48.503
-27.3115 31.9333 47.6776 -5.90834 37.7568 43.9037 15.4948 43.5802 40.1297

25 changes: 6 additions & 19 deletions tests/test_datasets/box_test_sphere_true_version6.vtk
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
# vtk DataFile Version 4.0
vtk output
ASCII
DATASET POLYDATA
DATASET STRUCTURED_GRID
DIMENSIONS 3 2 2
POINTS 12 float
-20 -55 -45 -4.37166 -55 43.6327 -42.9398 31.9333 -40.9551
-27.3115 31.9333 47.6776 1.40315 -49.1766 -48.774 17.0315 -49.1766 39.8587
-21.5367 37.7568 -44.729 -5.90834 37.7568 43.9037 22.8063 -43.3531 -52.5479
38.4346 -43.3531 36.0848 -0.133524 43.5802 -48.503 15.4948 43.5802 40.1297

VERTICES 12 24
1 0
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
-20 -55 -45 1.40315 -49.1766 -48.774 22.8063 -43.3531 -52.5479
-4.37166 -55 43.6327 17.0315 -49.1766 39.8587 38.4346 -43.3531 36.0848
-42.9398 31.9333 -40.9551 -21.5367 37.7568 -44.729 -0.133524 43.5802 -48.503
-27.3115 31.9333 47.6776 -5.90834 37.7568 43.9037 15.4948 43.5802 40.1297