Skip to content

Commit f6ac4ea

Browse files
author
fsalmoir
committed
changed some lines of code in plot method of vtkhandler class to make it more general and fast
1 parent 0795d4f commit f6ac4ea

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

pygem/gui.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,12 @@ def _run_simulation(self):
119119
new_mesh_points = free_form.modified_mesh_points
120120

121121
geo_handler.write(new_mesh_points, self.outfilename.get() + file_extension_in)
122-
122+
123+
if self.check_var_1.get() == 1:
124+
pg.utils.write_bounding_box(params, self.outfilename_lattice_orig.get() + '.vtk', False)
125+
if self.check_var_2.get() == 1:
126+
pg.utils.write_bounding_box(params, self.outfilename_lattice_mod.get() + '.vtk', True)
127+
123128
if file_extension_in in ['.vtk', '.stl', '.iges', '.igs']:
124129
figure_in = geo_handler.plot()
125130
figure_in.set_size_inches(4, 3)
@@ -128,11 +133,6 @@ def _run_simulation(self):
128133
figure_out = geo_handler.plot(self.outfilename.get() + file_extension_in)
129134
figure_out.set_size_inches(4, 3)
130135
FigureCanvasTkAgg(figure_out, master=self.mod_geo_frame).get_tk_widget().grid(row=1, column=0, padx=5, pady=5)
131-
132-
if self.check_var_1.get() == 1:
133-
pg.utils.write_bounding_box(params, self.outfilename_lattice_orig.get() + '.vtk', False)
134-
if self.check_var_2.get() == 1:
135-
pg.utils.write_bounding_box(params, self.outfilename_lattice_mod.get() + '.vtk', True)
136136

137137

138138
def _goto_website(self):

pygem/vtkhandler.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,28 +115,23 @@ def plot(self, plot_file=None, save_fig=False):
115115
else:
116116
self._check_filename_type(plot_file)
117117

118-
# Read the source file.
119-
reader = vtk.vtkUnstructuredGridReader()
118+
# Read the source file.
119+
reader = vtk.vtkDataSetReader()
120120
reader.SetFileName(plot_file)
121121
reader.Update()
122122

123123
data = reader.GetOutput()
124124
points = data.GetPoints()
125-
ncells = data.GetCells().GetNumberOfCells()
125+
ncells = data.GetNumberOfCells()
126126

127127
# for each cell it contains the indeces of the points that define the cell
128-
cells = np.zeros((ncells, 3))
129-
130-
for i in range(0, ncells):
131-
for j in range(0, 3):
132-
cells[i][j] = data.GetCell(i).GetPointId(j)
133-
134128
figure = plt.figure()
135129
axes = a3.Axes3D(figure)
136130
vtx = np.zeros((ncells, 3, 3))
137131
for i in range(0, ncells):
138132
for j in range(0, 3):
139-
vtx[i][j][0], vtx[i][j][1], vtx[i][j][2] = points.GetPoint(int(cells[i][j]))
133+
cell = data.GetCell(i).GetPointId(j)
134+
vtx[i][j][0], vtx[i][j][1], vtx[i][j][2] = points.GetPoint(int(cell))
140135
tri = a3.art3d.Poly3DCollection([vtx[i]])
141136
tri.set_color('b')
142137
tri.set_edgecolor('k')

0 commit comments

Comments
 (0)