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
3 changes: 0 additions & 3 deletions docs/source/code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,3 @@ Code Documentation
ffd_parameters
file_handler


.. automodule:: pygem
:members:
5 changes: 5 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
'sphinx.ext.ifconfig',
]

intersphinx_mapping = {'python': ('http://docs.python.org/2', None),
'numpy': ('http://docs.scipy.org/doc/numpy/', None),
'scipy': ('http://docs.scipy.org/doc/scipy/reference/', None),
'matplotlib': ('http://matplotlib.sourceforge.net/', None)}

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

Expand Down
19 changes: 11 additions & 8 deletions pygem/file_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def parse(self, filename):

:return: mesh_points: it is a `n_points`-by-3 matrix containing the coordinates of
the points of the mesh
:rtype: float numpy.ndarray
:rtype: numpy.ndarray

.. todo::

Expand Down Expand Up @@ -119,7 +119,7 @@ def write(self, mesh_points, filename):
the coordinates. mesh_points is a matrix that contains the new coordinates to
write in the unv file.

:param ndarray mesh_points: it is a `n_points`-by-3 matrix containing
:param numpy.ndarray mesh_points: it is a `n_points`-by-3 matrix containing
the coordinates of the points of the mesh
:param string filename: name of the output file.

Expand Down Expand Up @@ -164,7 +164,7 @@ def parse(self, filename):

:return: mesh_points: it is a `n_points`-by-3 matrix containing the coordinates of
the points of the mesh
:rtype: float numpy.ndarray
:rtype: numpy.ndarray

.. todo::

Expand Down Expand Up @@ -197,7 +197,7 @@ def write(self, mesh_points, filename):
the coordinates. mesh_points is a matrix that contains the new coordinates to
write in the vtk file.

:param ndarray mesh_points: it is a `n_points`-by-3 matrix containing
:param numpy.ndarray mesh_points: it is a `n_points`-by-3 matrix containing
the coordinates of the points of the mesh
:param string filename: name of the output file.

Expand Down Expand Up @@ -226,13 +226,11 @@ def write(self, mesh_points, filename):
writer = vtk.vtkDataSetWriter()
writer.SetFileName(self.outfile)


if vtk.VTK_MAJOR_VERSION <= 5:
writer.SetInput(data)
else:
writer.SetInputData(data)

#writer.SetInputData(data)
writer.Write()


Expand Down Expand Up @@ -302,11 +300,13 @@ def write(self, mesh_points, filename):
stl_mesh.save(self.outfile, mode=1, update_normals=True)


def plot(self, plot_file=None):
def plot(self, plot_file=None, save_fig=False):
"""
Method to plot an stl file. If `plot_file` is not given it plots `self.infile`.

:param string plot_file: the stl filename you want to plot.
:param bool save_fig: a flag to save the figure in png or not. If True the
plot is not shown.
"""
if plot_file is None:
plot_file = self.infile
Expand All @@ -326,7 +326,10 @@ def plot(self, plot_file=None):
axes.auto_scale_xyz(scale, scale, scale)

# Show the plot to the screen
pyplot.show()
if not save_fig:
pyplot.show()
else:
figure.savefig(plot_file.split('.')[0] + '.png')



Expand Down
4 changes: 2 additions & 2 deletions pygem/free_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ class FFD(object):
"""
Class that handles the Free Form Deformation on the mesh points.

:param class ffd_parameters: parameters of the Free Form Deformation.
:param FFDParameters ffd_parameters: parameters of the Free Form Deformation.
:param numpy.ndarray original_mesh_points: coordinates of the original points of the mesh.

:cvar class parameters: parameters of the Free Form Deformation.
:cvar FFDParameters parameters: parameters of the Free Form Deformation.
:cvar numpy.ndarray original_mesh_points: coordinates of the original points of the mesh.
The shape is `n_points`-by-3.
:cvar numpy.ndarray modified_mesh_points: coordinates of the points of the deformed mesh.
Expand Down
4 changes: 4 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@

import matplotlib
import nose

matplotlib.use('agg')

nose.main()
10 changes: 10 additions & 0 deletions tests/test_file_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,16 @@ def test_stl_write_comparison(self):
os.remove(outfilename)


def test_stl_plot_save_fig(self):
stl_handler = fh.StlHandler()
mesh_points = stl_handler.parse('tests/test_datasets/test_sphere.stl')
stl_handler.plot(save_fig=True)
if not os.path.isfile('tests/test_datasets/test_sphere.png'):
assert False
else:
os.remove('tests/test_datasets/test_sphere.png')


def test_stl_plot_failing_outfile_type(self):
stl_handler = fh.StlHandler()
with self.assertRaises(TypeError):
Expand Down