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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pygem.params.ffdparams.FFDParameters.save_points
================================================

.. currentmodule:: pygem.params.ffdparams

.. automethod:: FFDParameters.save_points
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pygem.params.rbfparams.RBFParameters.plot_points
================================================

.. currentmodule:: pygem.params.rbfparams

.. automethod:: RBFParameters.plot_points

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pygem.params.rbfparams.RBFParameters.save_points
================================================

.. currentmodule:: pygem.params.rbfparams

.. automethod:: RBFParameters.save_points
2 changes: 1 addition & 1 deletion docs/source/ffdparams.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ FFDParameters
FFDParameters.position_vertices
FFDParameters.read_parameters
FFDParameters.write_parameters
FFDParameters.save
FFDParameters.save_points
FFDParameters.build_bounding_box
FFDParameters.reset_deformation

Expand Down
3 changes: 2 additions & 1 deletion docs/source/rbfparams.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ RBFParameters
RBFParameters.n_control_points
RBFParameters.read_parameters
RBFParameters.write_parameters
RBFParameters.save
RBFParameters.save_points
RBFParameters.plot_points

.. autoclass:: RBFParameters
:members:
Expand Down
28 changes: 16 additions & 12 deletions pygem/params/ffdparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def __str__(self):
string += '\nposition_vertices = {}\n'.format(self.position_vertices)
return string

def save(self, filename, write_deformed=True):
def save_points(self, filename, write_deformed=True):
"""
Method that writes a vtk file containing the FFD lattice. This method
allows to visualize where the FFD control points are located before the
Expand All @@ -354,34 +354,38 @@ def save(self, filename, write_deformed=True):
>>> params.read_parameters(
>>> filename='tests/test_datasets/parameters_test_ffd_sphere.prm')
>>> params.save('tests/test_datasets/box_test_sphere.vtk')

.. note::
In order to visualize the points in Paraview, please select the
**Point Gaussian** representation.

"""
x = np.linspace(0, self.lenght_box[0], self.n_control_points[0])
y = np.linspace(0, self.lenght_box[1], self.n_control_points[1])
z = np.linspace(0, self.lenght_box[2], self.n_control_points[2])

lattice_y_coords, lattice_x_coords, lattice_z_coords = np.meshgrid(
y, x, z)
lattice_y_coords, lattice_x_coords, lattice_z_coords = np.meshgrid(y, x,
z)

if write_deformed:
box_points = np.array([
lattice_x_coords.ravel() +
self.array_mu_x.ravel() * self.lenght_box[0],
lattice_y_coords.ravel() +
lattice_x_coords.ravel() + self.array_mu_x.ravel() *
self.lenght_box[0], lattice_y_coords.ravel() +
self.array_mu_y.ravel() * self.lenght_box[1],
lattice_z_coords.ravel() +
self.array_mu_z.ravel() * self.lenght_box[2]
lattice_z_coords.ravel() + self.array_mu_z.ravel() *
self.lenght_box[2]
])
else:
box_points = np.array([
lattice_x_coords.ravel(),
lattice_y_coords.ravel(),
lattice_x_coords.ravel(), lattice_y_coords.ravel(),
lattice_z_coords.ravel()
])

n_rows = box_points.shape[1]

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

points = vtk.vtkPoints()

Expand Down
51 changes: 49 additions & 2 deletions pygem/params/rbfparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
import numpy as np
import vtk
import matplotlib.pyplot as plt


class RBFParameters(object):
Expand Down Expand Up @@ -193,7 +194,7 @@ def __str__(self):
string += '{}\n'.format(self.deformed_control_points)
return string

def save(self, filename, write_deformed=True):
def save_points(self, filename, write_deformed=True):
"""
Method that writes a vtk file containing the control points. This method
allows to visualize where the RBF control points are located before the
Expand All @@ -212,7 +213,12 @@ def save(self, filename, write_deformed=True):
>>> params = RBFParameters()
>>> params.read_parameters(
>>> filename='tests/test_datasets/parameters_rbf_cube.prm')
>>> params.save('tests/test_datasets/box_cube.vtk')
>>> params.save_points('tests/test_datasets/box_cube.vtk')

.. note::
In order to visualize the points in Paraview, please select the
**Point Gaussian** representation.

"""
box_points = self.deformed_control_points if write_deformed else self.original_control_points
points = vtk.vtkPoints()
Expand All @@ -227,3 +233,44 @@ def save(self, filename, write_deformed=True):
writer.SetFileName(filename)
writer.SetInputData(data)
writer.Write()


def plot_points(self, filename=None):
"""
Method to plot the control points. It is possible to save the resulting
figure.

:param str filename: if None the figure is shown, otherwise it is saved
on the specified `filename`. Default is None.
"""
fig = plt.figure(1)
axes = fig.add_subplot(111, projection='3d')
orig = axes.scatter(
self.original_control_points[:, 0],
self.original_control_points[:, 1],
self.original_control_points[:, 2],
c='blue',
marker='o')
defor = axes.scatter(
self.deformed_control_points[:, 0],
self.deformed_control_points[:, 1],
self.deformed_control_points[:, 2],
c='red',
marker='x')

axes.set_xlabel('X axis')
axes.set_ylabel('Y axis')
axes.set_zlabel('Z axis')

plt.legend(
(orig, defor), ('Original', 'Deformed'),
scatterpoints=1,
loc='lower left',
ncol=2,
fontsize=10)

# Show the plot to the screen
if filename is None:
plt.show()
else:
fig.savefig(filename)
205 changes: 0 additions & 205 deletions pygem/utils.py

This file was deleted.

Loading