diff --git a/docs/source/code.rst b/docs/source/code.rst index dd9d209..c445242 100644 --- a/docs/source/code.rst +++ b/docs/source/code.rst @@ -11,6 +11,3 @@ Code Documentation ffd_parameters file_handler - -.. automodule:: pygem - :members: diff --git a/docs/source/conf.py b/docs/source/conf.py index cc8cb40..7693d85 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -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'] diff --git a/pygem/file_handler.py b/pygem/file_handler.py index 1a57e80..79a9208 100644 --- a/pygem/file_handler.py +++ b/pygem/file_handler.py @@ -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:: @@ -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. @@ -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:: @@ -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. @@ -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() @@ -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 @@ -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') diff --git a/pygem/free_form.py b/pygem/free_form.py index 7b6a69d..e987428 100644 --- a/pygem/free_form.py +++ b/pygem/free_form.py @@ -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. diff --git a/test.py b/test.py index d9f86c2..67a4129 100644 --- a/test.py +++ b/test.py @@ -1,3 +1,7 @@ + +import matplotlib import nose +matplotlib.use('agg') + nose.main() \ No newline at end of file diff --git a/tests/test_file_handler.py b/tests/test_file_handler.py index b2b09ec..0b7d651 100644 --- a/tests/test_file_handler.py +++ b/tests/test_file_handler.py @@ -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):