diff --git a/pygem/affine.py b/pygem/affine.py index 26011e5..877730e 100644 --- a/pygem/affine.py +++ b/pygem/affine.py @@ -4,8 +4,8 @@ """ import math import sys -import numpy as np from functools import reduce +import numpy as np def angles2matrix(rot_z=0, rot_y=0, rot_x=0): diff --git a/pygem/freeform.py b/pygem/freeform.py index 997e453..4321b03 100644 --- a/pygem/freeform.py +++ b/pygem/freeform.py @@ -150,19 +150,19 @@ def perform(self): # shift_mesh_points needs to be transposed to be summed with mesh_points # apply inverse transformation to shifted mesh points - new_mesh_points = self._transform_points(np.transpose(shift_mesh_points) + - mesh_points, inverse_transformation) + \ - translation + new_mesh_points = self._transform_points( + np.transpose(shift_mesh_points) + mesh_points, + inverse_transformation) + translation # merge non-shifted mesh points with shifted ones self.modified_mesh_points = np.copy(self.original_mesh_points) - self.modified_mesh_points[(reference_frame_mesh_points[:,0] >= 0.) & - (reference_frame_mesh_points[:,0] <= 1.) & - (reference_frame_mesh_points[:,1] >= 0.) & - (reference_frame_mesh_points[:,1] <= 1.) & - (reference_frame_mesh_points[:,2] >= 0.) & - (reference_frame_mesh_points[:,2] <= 1.)] \ - = new_mesh_points + self.modified_mesh_points[(reference_frame_mesh_points[:, 0] >= 0.) + & (reference_frame_mesh_points[:, 0] <= 1.) & + (reference_frame_mesh_points[:, 1] >= 0.) & + (reference_frame_mesh_points[:, 1] <= 1.) & + (reference_frame_mesh_points[:, 2] >= 0.) & + (reference_frame_mesh_points[:, 2] <= + 1.)] = new_mesh_points @staticmethod def _transform_points(original_points, transformation): diff --git a/pygem/idw.py b/pygem/idw.py index 5687972..78255ca 100644 --- a/pygem/idw.py +++ b/pygem/idw.py @@ -25,21 +25,18 @@ {\\displaystyle\\sum_{j=1}^\\mathcal{N} w(\\mathrm{x},\\mathrm{x}_j)} u_k - where, in general, :math:`w(\\mathrm{x}, \\mathrm{x}_i)` represents the weighting function: .. math:: w(\\mathrm{x}, \\mathrm{x}_i) = \\| \\mathrm{x} - \\mathrm{x}_i \\|^{-p} - + being :math:`\\| \\mathrm{x} - \\mathrm{x}_i \\|^{-p} \\ge 0` is the Euclidean distance between :math:`\\mathrm{x}` and data point :math:`\\mathrm{x}_i` and :math:`p` is a power parameter, typically equal to 2. - """ import numpy as np - from scipy.spatial.distance import cdist @@ -91,7 +88,10 @@ def perform(self): """ def distance(u, v): - return np.linalg.norm(u - v, self.parameters.power) + """ + Norm of u - v + """ + return np.linalg.norm(u - v, ord=self.parameters.power) # Compute displacement of the control points displ = (self.parameters.deformed_control_points - diff --git a/pygem/igeshandler.py b/pygem/igeshandler.py index 9508372..e187a3d 100644 --- a/pygem/igeshandler.py +++ b/pygem/igeshandler.py @@ -1,7 +1,6 @@ """ Derived module from filehandler.py to handle iges and igs files. """ - from OCC.IGESControl import (IGESControl_Reader, IGESControl_Writer, IGESControl_Controller_Init) from OCC.IFSelect import IFSelect_RetDone diff --git a/pygem/openfhandler.py b/pygem/openfhandler.py index 09ed436..295f20b 100644 --- a/pygem/openfhandler.py +++ b/pygem/openfhandler.py @@ -11,8 +11,8 @@ class OpenFoamHandler(fh.FileHandler): :cvar string infile: name of the input file to be processed. :cvar string outfile: name of the output file where to write in. - :cvar list extensions: extensions of the input/output files. It is equal to [''] since - openFOAM files do not have extension. + :cvar list extensions: extensions of the input/output files. It + is equal to [''] since openFOAM files do not have extension. """ def __init__(self): @@ -21,12 +21,13 @@ def __init__(self): def parse(self, filename): """ - Method to parse the `filename`. It returns a matrix with all the coordinates. + Method to parse the `filename`. It returns a matrix with all + the coordinates. :param string filename: name of the input file. - :return: mesh_points: it is a `n_points`-by-3 matrix containing the coordinates of - the points of the mesh + :return: mesh_points: it is a `n_points`-by-3 matrix containing + the coordinates of the points of the mesh :rtype: numpy.ndarray .. todo:: @@ -58,12 +59,13 @@ def parse(self, filename): def write(self, mesh_points, filename): """ - Writes a openFOAM file, called filename, copying all the lines from self.filename but - the coordinates. mesh_points is a matrix that contains the new coordinates to - write in the openFOAM file. + Writes a openFOAM file, called filename, copying all the + lines from self.filename but the coordinates. mesh_points + is a matrix that contains the new coordinates to write in + the openFOAM file. - :param numpy.ndarray mesh_points: it is a `n_points`-by-3 matrix containing - the coordinates of the points of the mesh. + :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. .. todo:: DOCS @@ -82,8 +84,8 @@ def write(self, mesh_points, filename): for line in input_file: nrow += 1 if 20 < nrow < 21 + n_points: - output_file.write('(' + str(mesh_points[i][0]) + ' ' + str(mesh_points[i][1]) + \ - ' ' + str(mesh_points[i][2]) +')') + output_file.write('(' + str(mesh_points[i][0]) + ' ' + str( + mesh_points[i][1]) + ' ' + str(mesh_points[i][2]) + ')') output_file.write('\n') i += 1 else: diff --git a/pygem/params/__init__.py b/pygem/params/__init__.py index 97ce823..760055a 100644 --- a/pygem/params/__init__.py +++ b/pygem/params/__init__.py @@ -1,3 +1,6 @@ +""" +params init +""" from .rbfparams import RBFParameters from .ffdparams import FFDParameters from .idwparams import IDWParameters diff --git a/pygem/params/ffdparams.py b/pygem/params/ffdparams.py index 7ccf748..03094f4 100644 --- a/pygem/params/ffdparams.py +++ b/pygem/params/ffdparams.py @@ -1,5 +1,5 @@ """ -Utilities for reading and writing parameters files to perform the desired +Utilities for reading and writing parameters files to perform FFD geometrical morphing. """ try: @@ -7,15 +7,12 @@ except ImportError: import ConfigParser as configparser import os - import numpy as np +from OCC.Bnd import Bnd_Box from OCC.BRepBndLib import brepbndlib_Add from OCC.BRepMesh import BRepMesh_IncrementalMesh -from OCC.Bnd import Bnd_Box - import vtk import pygem.affine as at -from math import radians class FFDParameters(object): @@ -44,7 +41,7 @@ class FFDParameters(object): :Example: from file >>> import pygem.params as ffdp - >>> + >>> >>> # Reading an existing file >>> params1 = ffdp.FFDParameters() >>> params1.read_parameters( @@ -115,8 +112,8 @@ def rotation_matrix(self): :rtype: numpy.ndarray """ return at.angles2matrix( - radians(self.rot_angle[2]), radians(self.rot_angle[1]), - radians(self.rot_angle[0])) + np.radians(self.rot_angle[2]), np.radians(self.rot_angle[1]), + np.radians(self.rot_angle[0])) @property def position_vertices(self): @@ -213,69 +210,99 @@ def write_parameters(self, filename='parameters.prm'): output_string += 'n control points z: ' + str( self.n_control_points[2]) + '\n' - output_string += '\n# box lenght indicates the length of the FFD bounding box along the three canonical directions (x, y, z).\n' + output_string += '\n# box lenght indicates the length of the FFD ' + output_string += 'bounding box along the three canonical directions (x, y, z).\n' + output_string += '# It uses the local coordinate system.\n' - output_string += '# For example to create a 2 x 1.5 x 3 meters box use the following: lenght box: 2.0, 1.5, 3.0\n' + output_string += '# For example to create a 2 x 1.5 x 3 meters box ' + output_string += 'use the following: lenght box: 2.0, 1.5, 3.0\n' + output_string += 'box lenght x: ' + str(self.lenght_box[0]) + '\n' output_string += 'box lenght y: ' + str(self.lenght_box[1]) + '\n' output_string += 'box lenght z: ' + str(self.lenght_box[2]) + '\n' - output_string += '\n# box origin indicates the x, y, and z coordinates of the origin of the FFD bounding box. That is center of\n' - output_string += '# rotation of the bounding box. It corresponds to the point coordinates with position [0][0][0].\n' + output_string += '\n# box origin indicates the x, y, and z coordinates of ' + output_string += 'the origin of the FFD bounding box. That is center of\n' + + output_string += '# rotation of the bounding box. It corresponds to ' + output_string += 'the point coordinates with position [0][0][0].\n' + output_string += '# See section "Parameters weights" for more details.\n' - output_string += '# For example, if the origin is equal to 0., 0., 0., use the following: origin box: 0., 0., 0.\n' + output_string += '# For example, if the origin is equal to 0., 0., 0., use ' + output_string += 'the following: origin box: 0., 0., 0.\n' + output_string += 'box origin x: ' + str(self.origin_box[0]) + '\n' output_string += 'box origin y: ' + str(self.origin_box[1]) + '\n' output_string += 'box origin z: ' + str(self.origin_box[2]) + '\n' - output_string += '\n# rotation angle indicates the rotation angle around the x, y, and z axis of the FFD bounding box in degrees.\n' + output_string += '\n# rotation angle indicates the rotation angle ' + output_string += 'around the x, y, and z axis of the FFD bounding box in degrees.\n' + output_string += '# The rotation is done with respect to the box origin.\n' - output_string += '# For example, to rotate the box by 2 deg along the z direction, use the following: rotation angle: 0., 0., 2.\n' + output_string += '# For example, to rotate the box by 2 deg along the z ' + output_string += 'direction, use the following: rotation angle: 0., 0., 2.\n' + output_string += 'rotation angle x: ' + str(self.rot_angle[0]) + '\n' output_string += 'rotation angle y: ' + str(self.rot_angle[1]) + '\n' output_string += 'rotation angle z: ' + str(self.rot_angle[2]) + '\n' output_string += '\n\n[Parameters weights]\n' - output_string += '# This section describes the weights of the FFD control points.\n' + output_string += '# This section describes the weights of the FFD ' + output_string += 'control points.\n' + output_string += '# We adopt the following convention:\n' - output_string += '# For example with a 2x2x2 grid of control points we have to fill a 2x2x2 matrix of weights.\n' - output_string += '# If a weight is equal to zero you can discard the line since the default is zero.\n' + output_string += '# For example with a 2x2x2 grid of control points we ' + output_string += 'have to fill a 2x2x2 matrix of weights.\n' + + output_string += '# If a weight is equal to zero you can discard the line ' + output_string += 'since the default is zero.\n' + output_string += '#\n' output_string += '# | x index | y index | z index | weight |\n' output_string += '# --------------------------------------\n' output_string += '# | 0 | 0 | 0 | 1.0 |\n' - output_string += '# | 0 | 1 | 1 | 0.0 | --> you can erase this line without effects\n' + output_string += '# | 0 | 1 | 1 | 0.0 | --> you ' + output_string += 'can erase this line without effects\n' output_string += '# | 0 | 1 | 0 | -2.1 |\n' output_string += '# | 0 | 0 | 1 | 3.4 |\n' - output_string += '\n# parameter x collects the displacements along x, normalized with the box lenght x.' + output_string += '\n# parameter x collects the displacements along x, ' + output_string += 'normalized with the box lenght x.' + output_string += '\nparameter x:' offset = 1 for i in range(0, self.n_control_points[0]): for j in range(0, self.n_control_points[1]): for k in range(0, self.n_control_points[2]): - output_string += offset * ' ' + str(i) + ' ' + str(j) + ' ' + str(k) + \ - ' ' + str(self.array_mu_x[i][j][k]) + '\n' + output_string += offset * ' ' + str(i) + ' ' + str( + j) + ' ' + str(k) + ' ' + str( + self.array_mu_x[i][j][k]) + '\n' offset = 13 - output_string += '\n# parameter y collects the displacements along y, normalized with the box lenght y.' + output_string += '\n# parameter y collects the displacements along y, ' + output_string += 'normalized with the box lenght y.' + output_string += '\nparameter y:' offset = 1 for i in range(0, self.n_control_points[0]): for j in range(0, self.n_control_points[1]): for k in range(0, self.n_control_points[2]): - output_string += offset * ' ' + str(i) + ' ' + str(j) + ' ' + str(k) + \ - ' ' + str(self.array_mu_y[i][j][k]) + '\n' + output_string += offset * ' ' + str(i) + ' ' + str( + j) + ' ' + str(k) + ' ' + str( + self.array_mu_y[i][j][k]) + '\n' offset = 13 - output_string += '\n# parameter z collects the displacements along z, normalized with the box lenght z.' + output_string += '\n# parameter z collects the displacements along z, ' + output_string += 'normalized with the box lenght z.' + output_string += '\nparameter z:' offset = 1 for i in range(0, self.n_control_points[0]): for j in range(0, self.n_control_points[1]): for k in range(0, self.n_control_points[2]): - output_string += offset * ' ' + str(i) + ' ' + str(j) + ' ' + str(k) + \ - ' ' + str(self.array_mu_z[i][j][k]) + '\n' + output_string += offset * ' ' + str(i) + ' ' + str( + j) + ' ' + str(k) + ' ' + str( + self.array_mu_z[i][j][k]) + '\n' offset = 13 with open(filename, 'w') as f: diff --git a/pygem/params/idwparams.py b/pygem/params/idwparams.py index 8b4393b..97b8f75 100644 --- a/pygem/params/idwparams.py +++ b/pygem/params/idwparams.py @@ -1,5 +1,9 @@ -import numpy as np +""" +Utilities for reading and writing parameters files to perform IDW +geometrical morphing. +""" import os +import numpy as np try: import configparser as configparser except ImportError: diff --git a/pygem/params/rbfparams.py b/pygem/params/rbfparams.py index a45892d..385985e 100644 --- a/pygem/params/rbfparams.py +++ b/pygem/params/rbfparams.py @@ -1,5 +1,5 @@ """ -Utilities for reading and writing parameters files to perform the desired +Utilities for reading and writing parameters files to perform RBF geometrical morphing. """ try: @@ -7,8 +7,8 @@ except ImportError: import ConfigParser as configparser import os - import numpy as np +import vtk class RBFParameters(object): @@ -125,8 +125,9 @@ def write_parameters(self, filename='parameters_rbf.prm'): output_file.write( '# This section describes the radial basis functions shape.\n') - output_file.write('\n# basis funtion is the name of the basis functions to use in the transformation. ' + \ - 'The functions\n') + output_file.write( + '\n# basis funtion is the name of the basis functions to use in the transformation. The functions\n' + ) output_file.write( '# implemented so far are: gaussian_spline, multi_quadratic_biharmonic_spline,\n' ) @@ -137,8 +138,9 @@ def write_parameters(self, filename='parameters_rbf.prm'): '# For a comprehensive list with details see the class RBF.\n') output_file.write('basis function: ' + str(self.basis) + '\n') - output_file.write('\n# radius is the scaling parameter r that affects the shape of the basis functions. ' + \ - 'See the documentation\n') + output_file.write( + '\n# radius is the scaling parameter r that affects the shape of the basis functions. See the documentation\n' + ) output_file.write('# of the class RBF for details.\n') output_file.write('radius: ' + str(self.radius) + '\n') output_file.write( @@ -150,23 +152,27 @@ def write_parameters(self, filename='parameters_rbf.prm'): output_file.write( '# This section describes the RBF control points.\n') - output_file.write('\n# original control points collects the coordinates of the interpolation ' + \ - 'control points before the deformation.\n') + output_file.write( + '\n# original control points collects the coordinates of the interpolation control points before the deformation.\n' + ) output_file.write('original control points:') offset = 1 for i in range(0, self.n_control_points): - output_file.write(offset * ' ' + str(self.original_control_points[i][0]) + ' ' + \ - str(self.original_control_points[i][1]) + ' ' + \ + output_file.write( + offset * ' ' + str(self.original_control_points[i][0]) + + ' ' + str(self.original_control_points[i][1]) + ' ' + str(self.original_control_points[i][2]) + '\n') offset = 25 - output_file.write('\n# deformed control points collects the coordinates of the interpolation ' + \ - 'control points after the deformation.\n') + output_file.write( + '\n# deformed control points collects the coordinates of the interpolation control points after the deformation.\n' + ) output_file.write('deformed control points:') offset = 1 for i in range(0, self.n_control_points): - output_file.write(offset * ' ' + str(self.deformed_control_points[i][0]) + ' ' + \ - str(self.deformed_control_points[i][1]) + ' ' + \ + output_file.write( + offset * ' ' + str(self.deformed_control_points[i][0]) + + ' ' + str(self.deformed_control_points[i][1]) + ' ' + str(self.deformed_control_points[i][2]) + '\n') offset = 25 @@ -200,7 +206,7 @@ def save(self, filename, write_deformed=True): :Example: >>> from pygem.params import RBFParameters - >>> + >>> >>> params = RBFParameters() >>> params.read_parameters( >>> filename='tests/test_datasets/parameters_rbf_cube.prm') @@ -217,8 +223,5 @@ def save(self, filename, write_deformed=True): writer = vtk.vtkPolyDataWriter() writer.SetFileName(filename) - if vtk.VTK_MAJOR_VERSION <= 5: - writer.SetInput(data) - else: - writer.SetInputData(data) + writer.SetInputData(data) writer.Write() diff --git a/pygem/stephandler.py b/pygem/stephandler.py index c36b038..2424eda 100644 --- a/pygem/stephandler.py +++ b/pygem/stephandler.py @@ -1,11 +1,9 @@ """ Derived module from nurbshandler.py to handle step and stp files. """ - from OCC.Interface import Interface_Static_SetCVal from OCC.STEPControl import STEPControl_Writer, STEPControl_Reader, STEPControl_AsIs from OCC.IFSelect import IFSelect_RetDone - from pygem.nurbshandler import NurbsHandler diff --git a/pygem/stlhandler.py b/pygem/stlhandler.py index d247533..8d1ca97 100644 --- a/pygem/stlhandler.py +++ b/pygem/stlhandler.py @@ -86,10 +86,7 @@ def write(self, mesh_points, filename, write_bin=False): writer = vtk.vtkSTLWriter() writer.SetFileName(self.outfile) - if vtk.VTK_MAJOR_VERSION <= 5: - writer.SetInput(data) - else: - writer.SetInputData(data) + writer.SetInputData(data) if write_bin: writer.SetFileTypeToBinary() @@ -140,12 +137,14 @@ def plot(self, plot_file=None, save_fig=False): axes.add_collection3d(tri) ## Get the limits of the axis and center the geometry - max_dim = np.array([np.max(vtx[:,:,0]), \ - np.max(vtx[:,:,1]), \ - np.max(vtx[:,:,2])]) - min_dim = np.array([np.min(vtx[:,:,0]), \ - np.min(vtx[:,:,1]), \ - np.min(vtx[:,:,2])]) + max_dim = np.array( + [np.max(vtx[:, :, 0]), + np.max(vtx[:, :, 1]), + np.max(vtx[:, :, 2])]) + min_dim = np.array( + [np.min(vtx[:, :, 0]), + np.min(vtx[:, :, 1]), + np.min(vtx[:, :, 2])]) max_lenght = np.max(max_dim - min_dim) axes.set_xlim(-.6 * max_lenght + (max_dim[0] + min_dim[0]) / 2, @@ -185,10 +184,7 @@ def show(self, show_file=None): # Create the mapper that corresponds the objects of the vtk file # into graphics elements mapper = vtk.vtkDataSetMapper() - if vtk.VTK_MAJOR_VERSION <= 5: - mapper.SetInput(output) - else: - mapper.SetInputData(output) + mapper.SetInputData(output) mapper.SetScalarRange(scalar_range) # Create the Actor diff --git a/pygem/unvhandler.py b/pygem/unvhandler.py index 6b67b46..e54b09a 100644 --- a/pygem/unvhandler.py +++ b/pygem/unvhandler.py @@ -11,7 +11,8 @@ class UnvHandler(fh.FileHandler): :cvar string infile: name of the input file to be processed. :cvar string outfile: name of the output file where to write in. - :cvar list extensions: extensions of the input/output files. It is equal to ['.unv']. + :cvar list extensions: extensions of the input/output files. + It is equal to ['.unv']. """ def __init__(self): @@ -20,13 +21,14 @@ def __init__(self): def parse(self, filename): """ - Method to parse the file `filename`. It returns a matrix with all the coordinates. - It reads only the section 2411 of the unv files and it assumes there are only triangles. + Method to parse the file `filename`. It returns a matrix with + all the coordinates. It reads only the section 2411 of the unv + files and it assumes there are only triangles. :param string filename: name of the input file. - - :return: mesh_points: it is a `n_points`-by-3 matrix containing the coordinates of - the points of the mesh. + + :return: mesh_points: it is a `n_points`-by-3 matrix containing + the coordinates of the points of the mesh. :rtype: numpy.ndarray """ self._check_filename_type(filename) @@ -59,12 +61,12 @@ def parse(self, filename): def write(self, mesh_points, filename): """ - Writes a unv file, called filename, copying all the lines from self.filename but - the coordinates. mesh_points is a matrix that contains the new coordinates to - write in the unv file. + Writes a unv file, called filename, copying all the lines from + `self.filename` but the coordinates. mesh_points is a matrix + that contains the new coordinates to write in the unv file. - :param numpy.ndarray mesh_points: it is a `n_points`-by-3 matrix containing - the coordinates of the points of the mesh + :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. """ self._check_filename_type(filename) diff --git a/pygem/utils.py b/pygem/utils.py index bfd484a..46bea79 100644 --- a/pygem/utils.py +++ b/pygem/utils.py @@ -24,7 +24,7 @@ def write_bounding_box(parameters, outfile, write_deformed=True): >>> import pygem.utils as ut >>> import pygem.params as pars >>> import numpy as np - >>> + >>> >>> params = pars.FFDParameters() >>> params.read_parameters(filename='tests/test_datasets/parameters_test_ffd_sphere.prm') >>> ut.write_bounding_box(params, 'tests/test_datasets/box_test_sphere.vtk') @@ -39,18 +39,25 @@ def write_bounding_box(parameters, outfile, write_deformed=True): aux_y, aux_x, aux_z) if write_deformed: - box_points = np.array([ \ - lattice_x_coords.ravel() + parameters.array_mu_x.ravel() * parameters.lenght_box[0], \ - lattice_y_coords.ravel() + parameters.array_mu_y.ravel() * parameters.lenght_box[1], \ - lattice_z_coords.ravel() + parameters.array_mu_z.ravel() * parameters.lenght_box[2]]) + box_points = np.array([ + lattice_x_coords.ravel() + + parameters.array_mu_x.ravel() * parameters.lenght_box[0], + lattice_y_coords.ravel() + + parameters.array_mu_y.ravel() * parameters.lenght_box[1], + lattice_z_coords.ravel() + + parameters.array_mu_z.ravel() * parameters.lenght_box[2] + ]) else: - box_points = np.array([lattice_x_coords.ravel(), lattice_y_coords.ravel(), \ - lattice_z_coords.ravel()]) + 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))) + box_points = np.dot(parameters.rotation_matrix, box_points) + np.transpose( + np.tile(parameters.origin_box, (n_rows, 1))) # step necessary to set the correct order to the box points for vtkStructuredGrid: # Data in vtkStructuredGrid are ordered with x increasing fastest, then y, then z @@ -113,23 +120,29 @@ def plot_rbf_control_points(parameters, save_fig=False): """ fig = plt.figure(1) axes = fig.add_subplot(111, projection='3d') - orig = axes.scatter(parameters.original_control_points[:, 0], \ - parameters.original_control_points[:, 1], \ - parameters.original_control_points[:, 2], c='blue', marker='o') - defor = axes.scatter(parameters.deformed_control_points[:, 0], \ - parameters.deformed_control_points[:, 1], \ - parameters.deformed_control_points[:, 2], c='red', marker='x') + orig = axes.scatter( + parameters.original_control_points[:, 0], + parameters.original_control_points[:, 1], + parameters.original_control_points[:, 2], + c='blue', + marker='o') + defor = axes.scatter( + parameters.deformed_control_points[:, 0], + parameters.deformed_control_points[:, 1], + parameters.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) + plt.legend( + (orig, defor), ('Original', 'Deformed'), + scatterpoints=1, + loc='lower left', + ncol=2, + fontsize=10) # Show the plot to the screen if not save_fig: @@ -152,7 +165,7 @@ def write_points_in_vtp(points, outfile='points.vtp', color=None): >>> import pygem.utils as ut >>> import numpy as np - + >>> >>> ctrl_points = np.arange(9).reshape(3, 3) >>> ut.write_points_in_vtp(ctrl_points, 'example_points.vtp', color=(255, 0, 0)) """ @@ -177,13 +190,8 @@ def write_points_in_vtp(points, outfile='points.vtp', color=None): polydata.SetVerts(Vertices) polydata.GetPointData().SetScalars(Colors) polydata.Modified() - if vtk.VTK_MAJOR_VERSION <= 5: - polydata.Update() writer = vtk.vtkXMLPolyDataWriter() writer.SetFileName(outfile) - if vtk.VTK_MAJOR_VERSION <= 5: - writer.SetInput(polydata) - else: - writer.SetInputData(polydata) + writer.SetInputData(polydata) writer.Write() diff --git a/pygem/vtkhandler.py b/pygem/vtkhandler.py index 3badccd..fa27fa7 100644 --- a/pygem/vtkhandler.py +++ b/pygem/vtkhandler.py @@ -180,10 +180,7 @@ def show(self, show_file=None): # Create the mapper that corresponds the objects of the vtk file # into graphics elements mapper = vtk.vtkDataSetMapper() - if vtk.VTK_MAJOR_VERSION <= 5: - mapper.SetInput(output) - else: - mapper.SetInputData(output) + mapper.SetInputData(output) mapper.SetScalarRange(scalar_range) # Create the Actor diff --git a/start_gui.py b/start_gui.py deleted file mode 100644 index 87de27d..0000000 --- a/start_gui.py +++ /dev/null @@ -1,4 +0,0 @@ -import pygem as pg - -interface = pg.gui.Gui() -interface.start()