Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_tensor_rotation_y():
transform = vtk.vtkTransform()
transform.RotateY(20)
transform.Update()
rot_matrix = transform.GetMatrix()
# rot_matrix.Invert() # <-- this should not be necessary
trans = pv.trans_from_matrix(rot_matrix)
s_test = stress.copy().reshape(1, -1)
_binary_reader.tensor_arbitrary(s_test, trans)
assert np.allclose(s_test, stress_rot_y)
def test_tensor_rotation_x():
transform = vtk.vtkTransform()
transform.RotateX(20)
transform.Update()
rot_matrix = transform.GetMatrix()
# rot_matrix.Invert() # <-- this should not be necessary
trans = pv.trans_from_matrix(rot_matrix)
s_test = stress.copy().reshape(1, -1)
_binary_reader.tensor_arbitrary(s_test, trans)
assert np.allclose(s_test, stress_rot_x)
def test_transform():
grid = GRID.copy()
trans = vtk.vtkTransform()
trans.RotateX(30)
trans.RotateY(30)
trans.RotateZ(30)
trans.Translate(1, 1, 2)
trans.Update()
grid_a = grid.copy()
grid_b = grid.copy()
grid_c = grid.copy()
grid_a.transform(trans)
grid_b.transform(trans.GetMatrix())
grid_c.transform(pyvista.trans_from_matrix(trans.GetMatrix()))
assert np.allclose(grid_a.points, grid_b.points)
assert np.allclose(grid_a.points, grid_c.points)
rang = 360.0 / self.n_sector
for i in range(self.n_sector):
# transform to standard position, rotate about Z axis,
# transform back
transform = vtk.vtkTransform()
transform.RotateZ(rang*i)
transform.Update()
rot_matrix = transform.GetMatrix()
if cs_cord > 1:
temp_matrix = vtk.vtkMatrix4x4()
rot_matrix.Multiply4x4(i_matrix, rot_matrix, temp_matrix)
rot_matrix.Multiply4x4(temp_matrix, matrix, rot_matrix)
trans = pv.trans_from_matrix(rot_matrix)
if tensor:
_binary_reader.tensor_arbitrary(full_result[i], trans)
else:
_binary_reader.affline_transform(full_result[i], trans)
return full_result
rang = 360.0 / self.n_sector
for i in range(self.n_sector):
# transform to standard position, rotate about Z axis,
# transform back
transform = vtk.vtkTransform()
transform.RotateZ(rang*i)
transform.Update()
rot_matrix = transform.GetMatrix()
if cs_cord > 1:
temp_matrix = vtk.vtkMatrix4x4()
rot_matrix.Multiply4x4(i_matrix, rot_matrix, temp_matrix)
rot_matrix.Multiply4x4(temp_matrix, matrix, rot_matrix)
trans = pv.trans_from_matrix(rot_matrix)
_binary_reader.tensor_arbitrary(full_result[i], trans)
return full_result
def transform(self, trans):
"""Compute a transformation in place using a 4x4 transform.
Parameters
----------
trans : vtk.vtkMatrix4x4, vtk.vtkTransform, or np.ndarray
Accepts a vtk transformation object or a 4x4 transformation matrix.
"""
if isinstance(trans, vtk.vtkMatrix4x4):
t = pyvista.trans_from_matrix(trans)
elif isinstance(trans, vtk.vtkTransform):
t = pyvista.trans_from_matrix(trans.GetMatrix())
elif isinstance(trans, np.ndarray):
if trans.shape[0] != 4 or trans.shape[1] != 4:
raise Exception('Transformation array must be 4x4')
t = trans
else:
raise TypeError('Input transform must be either:\n'
'\tvtk.vtkMatrix4x4\n'
'\tvtk.vtkTransform\n'
'\t4x4 np.ndarray\n')
x = (self.points*t[0, :3]).sum(1) + t[0, -1]
y = (self.points*t[1, :3]).sum(1) + t[1, -1]
z = (self.points*t[2, :3]).sum(1) + t[2, -1]