Skip to content

Commit

Permalink
fixing tests
Browse files Browse the repository at this point in the history
moving the contour filter
  • Loading branch information
SteveDoyle2 committed Jun 12, 2018
1 parent 01b52ff commit 892dfa1
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 140 deletions.
3 changes: 0 additions & 3 deletions pyNastran/bdf/cards/test/test_coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,14 +501,11 @@ def test_cord2_rcs_03(self):
xyz_cp, nids, icp_transform, cid=0)
array_equal(xyz_cid0_actual, xyz_cid0_xform)
assert array_equal(nids, array([30, 31, 32]))
model2.nodes.nids = nid_cp_cd[:, 0]


for cid in [30, 31, 32]:
unused_xyz_cid_a = model.transform_xyzcp_to_xyz_cid(
xyz_cp, nids, icp_transform, cid=cid)
unused_xyz_cid_b = model2.transform_xyzcp_to_xyz_cid(
xyz_cp, nids, icp_transform, cid=cid, atol=None)
#assert np.allclose(xyz_cid_a, xyz_cid_b), '%s' % np.isclose(xyz_cid_a, xyz_cid_b)

#print(xyz_cid_a)
Expand Down
13 changes: 0 additions & 13 deletions pyNastran/converters/aflr/ugrid/test_ugrid_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,6 @@ def test_ugrid_gui_01(self):
#test.load_ugrid_geometry(ugrid_filename, name='main', plot=True)
#test.load_ugrid3d_geometry(ugrid_filename, name='main', plot=True)

def test_ugrid_gui_02(self):
"""tests plate_with_circular_hole"""
bdf_filename = os.path.join(NASTRAN_PATH, 'plate_with_circular_hole', 'a101x.dat')
ugrid_filename = os.path.join(NASTRAN_PATH, 'plate_with_circular_hole', 'a101x.b8.ugrid')
log = get_logger(level='warning')

with self.assertRaises(RuntimeError):
nastran_to_ugrid(bdf_filename, ugrid_filename_out=ugrid_filename,
properties=None, check_shells=True, check_solids=False, log=log)
#assert os.path.exists(ugrid_filename), ugrid_filename
#test = UGRID_GUI()
#test.load_ugrid_geometry(ugrid_filename, name='main', plot=True)

def test_ugrid2d_gui(self):
"""simple UGRID2D model"""
ugrid_filename = 'quad_tri.ugrid'
Expand Down
124 changes: 0 additions & 124 deletions pyNastran/gui/gui_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2206,130 +2206,6 @@ def add_geometry(self):
self.rend.AddActor(self.geom_actor)
self.build_glyph()

def _make_contour_filter(self): # pragma: no cover
"""trying to make model lines...doesn't work"""
if not self.make_contour_filter:
return

self.contour_filter = vtk.vtkContourFilter()

if 0:
# doesn't work...in progress
geometry_filter = vtk.vtkGeometryFilter()
geometry_filter.SetInputData(self.grid_selected)
geometry_filter.Update()
poly_data = geometry_filter.GetOutput()

self.contour_filter.SetInputData(poly_data)
elif 0: # pragma: no cover
# doesn't work
self.contour_filter.SetInputData(self.grid_selected)
elif 1:
# https://blog.kitware.com/cell-set-as-unstructured-grid/
self.contour_filter.SetInputData(self.grid)
else:
raise RuntimeError('invalid contour_filter option')
#self.contour_filter.GenerateValues(1, 10, 10)
#self.contour_filter.SetComputeScalars(1)
#contour_filter.SetInputConnection(self.grid_selected.GetOutputPort())
#self.contour_filter.SetInputData(None)
self.contour_filter.ComputeScalarsOff()
self.contour_filter.ComputeNormalsOff()


# Connect the segments of the conours into polylines
contour_stripper = vtk.vtkStripper()
contour_stripper.SetInputConnection(self.contour_filter.GetOutputPort())
contour_stripper.Update()

number_of_contour_lines = contour_stripper.GetOutput().GetNumberOfLines()
print('There are %s contours lines.' % number_of_contour_lines)

include_labels = False
if include_labels:
points = contour_stripper.GetOutput().GetPoints()
cells = contour_stripper.GetOutput().GetLines()
scalars = contour_stripper.GetOutput().GetPointData().GetScalars()

label_poly_data.SetPoints(label_points)
label_poly_data.GetPointData().SetScalars(label_scalars)

# The labeled data mapper will place labels at the points
label_mapper = vtk.vtkLabeledDataMapper()
label_mapper.SetFieldDataName("Isovalues")
#if vtk.VTK_MAJOR_VERSION <= 5:
#label_mapper.SetInput(label_poly_data)
#else:
label_mapper.SetInputData(label_poly_data)

label_mapper.SetLabelModeToLabelScalars()
label_mapper.SetLabelFormat("%6.2f")

label_mapper.SetLabelModeToLabelScalars()
label_mapper.SetLabelFormat("%6.2f")

isolabels_actor = vtk.vtkActor2D()
isolabels_actor.SetMapper(label_mapper)

contour_mapper = vtk.vtkPolyDataMapper()
contour_mapper.SetInputConnection(contour_stripper.GetOutputPort())
contour_mapper.ScalarVisibilityOff()

isolines_actor = vtk.vtkActor()
isolines_actor.SetMapper(contour_mapper)
isolines_actor.GetProperty().SetColor(0., 0., 0.)

# Add the actors to the scene
self.rend.AddActor(isolines_actor)
if include_labels:
self.rend.AddActor(isolabels_actor)

self.contour_mapper = contour_mapper
self.contour_stripper = contour_stripper
self.contour_lines_actor = isolines_actor
self.contour_lines_actor.VisibilityOff()

def update_contour_filter(self, nlabels, location, min_value=None, max_value=None):
"""update the contour lines"""
if not self.make_contour_filter:
return
if nlabels is None:
nlabels = 11
if location == 'centroid': # node/centroid
self.contour_lines_actor.VisibilityOff()
#self.contour_mapper.SetScalarModeToUseCellData()
#res_data = self.grid.GetCellData().GetScalars()
return
elif location == 'node':
#self.contour_mapper.SetScalarModeToUsePointData()
res_data = self.grid.GetPointData().GetScalars()
else:
raise RuntimeError('location=%r' % location)

self.contour_lines_actor.VisibilityOn()
number_of_cuts = nlabels - 1
if min_value is None or max_value is None:
data_range = res_data.GetRange()
if min_value is None:
min_value = data_range[0]
if max_value is None:
max_value = data_range[1]

self.contour_filter.GenerateValues(
number_of_cuts,
0.99 * min_value,
0.99 * max_value)

self.contour_filter.Modified()
#self.contour_stripper.Modified()
self.contour_mapper.Modified()
#self.contour_filter.Update()
#self.contour_stripper.Update()
#self.contour_mapper.Update()

number_of_contour_lines = self.contour_stripper.GetOutput().GetNumberOfLines()
self.log.info('There are %s contours lines.' % number_of_contour_lines)

def build_glyph(self):
"""builds the glyph actor"""
grid = self.grid
Expand Down
125 changes: 125 additions & 0 deletions pyNastran/gui/qt_files/gui_qt_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,131 @@ def duplicate_alternate_vtk_grid(self, name, name_duplicate_from, color=None, li
if follower_nodes is not None:
self.follower_nodes[name] = follower_nodes

def _make_contour_filter(self): # pragma: no cover
"""trying to make model lines...doesn't work"""
if not self.make_contour_filter:
return

self.contour_filter = vtk.vtkContourFilter()

if 0:
# doesn't work...in progress
geometry_filter = vtk.vtkGeometryFilter()
geometry_filter.SetInputData(self.grid_selected)
geometry_filter.Update()
poly_data = geometry_filter.GetOutput()

self.contour_filter.SetInputData(poly_data)
elif 0: # pragma: no cover
# doesn't work
self.contour_filter.SetInputData(self.grid_selected)
elif 1:
# https://blog.kitware.com/cell-set-as-unstructured-grid/
self.contour_filter.SetInputData(self.grid)
else:
raise RuntimeError('invalid contour_filter option')
#self.contour_filter.GenerateValues(1, 10, 10)
#self.contour_filter.SetComputeScalars(1)
#contour_filter.SetInputConnection(self.grid_selected.GetOutputPort())
#self.contour_filter.SetInputData(None)
self.contour_filter.ComputeScalarsOff()
self.contour_filter.ComputeNormalsOff()


# Connect the segments of the conours into polylines
contour_stripper = vtk.vtkStripper()
contour_stripper.SetInputConnection(self.contour_filter.GetOutputPort())
contour_stripper.Update()

number_of_contour_lines = contour_stripper.GetOutput().GetNumberOfLines()
print('There are %s contours lines.' % number_of_contour_lines)

include_labels = False
if include_labels:
points = contour_stripper.GetOutput().GetPoints()
cells = contour_stripper.GetOutput().GetLines()
scalars = contour_stripper.GetOutput().GetPointData().GetScalars()

label_poly_data.SetPoints(label_points)
label_poly_data.GetPointData().SetScalars(label_scalars)

# The labeled data mapper will place labels at the points
label_mapper = vtk.vtkLabeledDataMapper()
label_mapper.SetFieldDataName("Isovalues")
#if vtk.VTK_MAJOR_VERSION <= 5:
#label_mapper.SetInput(label_poly_data)
#else:
label_mapper.SetInputData(label_poly_data)

label_mapper.SetLabelModeToLabelScalars()
label_mapper.SetLabelFormat("%6.2f")

label_mapper.SetLabelModeToLabelScalars()
label_mapper.SetLabelFormat("%6.2f")

isolabels_actor = vtk.vtkActor2D()
isolabels_actor.SetMapper(label_mapper)

contour_mapper = vtk.vtkPolyDataMapper()
contour_mapper.SetInputConnection(contour_stripper.GetOutputPort())
contour_mapper.ScalarVisibilityOff()

isolines_actor = vtk.vtkActor()
isolines_actor.SetMapper(contour_mapper)
isolines_actor.GetProperty().SetColor(0., 0., 0.)

# Add the actors to the scene
self.rend.AddActor(isolines_actor)
if include_labels:
self.rend.AddActor(isolabels_actor)

self.contour_mapper = contour_mapper
self.contour_stripper = contour_stripper
self.contour_lines_actor = isolines_actor
self.contour_lines_actor.VisibilityOff()

def update_contour_filter(self, nlabels, location, min_value=None, max_value=None):
"""update the contour lines"""
if not self.make_contour_filter:
return
if nlabels is None:
nlabels = 11
if location == 'centroid': # node/centroid
self.contour_lines_actor.VisibilityOff()
#self.contour_mapper.SetScalarModeToUseCellData()
#res_data = self.grid.GetCellData().GetScalars()
return
elif location == 'node':
#self.contour_mapper.SetScalarModeToUsePointData()
res_data = self.grid.GetPointData().GetScalars()
else:
raise RuntimeError('location=%r' % location)

self.contour_lines_actor.VisibilityOn()
number_of_cuts = nlabels - 1
if min_value is None or max_value is None:
data_range = res_data.GetRange()
if min_value is None:
min_value = data_range[0]
if max_value is None:
max_value = data_range[1]

self.contour_filter.GenerateValues(
number_of_cuts,
0.99 * min_value,
0.99 * max_value)

self.contour_filter.Modified()
#self.contour_stripper.Modified()
self.contour_mapper.Modified()
#self.contour_filter.Update()
#self.contour_stripper.Update()
#self.contour_mapper.Update()

number_of_contour_lines = self.contour_stripper.GetOutput().GetNumberOfLines()
self.log.info('There are %s contours lines.' % number_of_contour_lines)


def _get_normalized_data(case):
"""helper method for ``_get_fringe_data``"""
#def _get_normalized_data(result_case):
Expand Down

0 comments on commit 892dfa1

Please sign in to comment.