def test_valid_set_texture_with_jpg_format(vtk_overlay_with_gradient_image): input_file = 'tests/data/models/liver.ply' model = VTKSurfaceModel(input_file, colors.red) model.set_texture('tests/data/images/image0232.jpg') image, widget, _, app = vtk_overlay_with_gradient_image widget.add_vtk_actor(model.actor) widget.show() #app.exec_() return model
def test_set_texture_regression(vtk_overlay_with_gradient_image): in_github_ci = os.environ.get('CI') in_gitlab_ci = os.environ.get('GITLAB_CI') print("Gitlab_CI: " + str(in_gitlab_ci)) print("Github CI: " + str(in_github_ci)) if sys.platform == "darwin": pytest.skip("Test not working on Mac runner \ because the widget size is different") if in_github_ci and sys.platform.startswith("linux"): pytest.skip("Test not working on Linux runner \ because of unknown issue, see #60.") if in_github_ci and sys.platform.startswith("win"): pytest.skip("Skip on Windows on GitHub CI (use of MESA messes up \ result") input_file = 'tests/data/models/liver.ply' model = VTKSurfaceModel(input_file, colors.red) model.set_texture('tests/data/images/image0232.png') image, widget, _, _, app = vtk_overlay_with_gradient_image widget.resize(400, 400) widget.add_vtk_actor(model.actor) widget.show() # Read the saved scene and compare it with the current scene. screenshot_filename = 'tests/data/images/set_texture_test.png' screenshot = cv2.imread(screenshot_filename) # OpenCV uses BGR while VTK uses RGB. screenshot = cv2.cvtColor(screenshot, cv2.COLOR_BGR2RGB) current_scene = widget.convert_scene_to_numpy_array() tmp_dir = 'tests/output' if not os.path.isdir(tmp_dir): os.makedirs(tmp_dir) cv2.imwrite(os.path.join(tmp_dir, 'screenshot.png'), screenshot) cv2.imwrite(os.path.join(tmp_dir, 'current_scene.png'), current_scene) # As the rendered images in Ubuntu, Mac and Windows are different, # i.e., the pixel values are slightly different at the same location, # we add some threshold for comparison. # It checks if the number of values (in any channel) # that are different by more than 3 is less than 5 per cent # of the total number of pixels in the image. diff = abs(screenshot - current_scene) assert (np.sum( (diff > 3).astype(int)) / (screenshot.shape[0] * screenshot.shape[1]) * screenshot.shape[2]) < 0.05
def test_set_texture_regression(vtk_overlay_with_gradient_image): in_github_ci = os.environ.get('CI') in_gitlab_ci = os.environ.get('GITLAB_CI') print("Gitlab_CI: " + str(in_gitlab_ci)) print("Github CI: " + str(in_github_ci)) if sys.platform == "darwin": pass #pytest.skip("Test not working on Mac runner \ # because the widget size is different") if in_github_ci and sys.platform.startswith("linux"): pass #pytest.skip("Test not working on Linux runner \ # because of unknown issue, see #60.") if in_github_ci and sys.platform.startswith("win"): pass #pytest.skip("Skip on Windows on GitHub CI (use of MESA messes up \ # result") input_file = 'tests/data/models/liver.ply' model = VTKSurfaceModel(input_file, colors.red) model.set_texture('tests/data/images/image0232.png') image, widget, _, app = vtk_overlay_with_gradient_image widget.resize(400, 400) widget.add_vtk_actor(model.actor) widget.show() # Read the saved scene and compare it with the current scene. screenshot_filename = 'tests/data/images/set_texture_test.png' screenshot = cv2.imread(screenshot_filename) # OpenCV uses BGR while VTK uses RGB. screenshot = cv2.cvtColor(screenshot, cv2.COLOR_BGR2RGB) current_scene = widget.convert_scene_to_numpy_array() tmp_dir = 'tests/output' if not os.path.isdir(tmp_dir): os.makedirs(tmp_dir) cv2.imwrite(os.path.join(tmp_dir, 'screenshot.png'), screenshot) cv2.imwrite(os.path.join(tmp_dir, 'current_scene.png'), current_scene) # As the rendered images in Ubuntu, Mac and Windows are different, we'll # use the are similar function from sksurgery image assert are_similar(screenshot, current_scene, threshold=0.995, metric=cv2.TM_CCOEFF_NORMED, mean_threshold=0.005)
def test_valid_set_texture_with_png_format(vtk_overlay_with_gradient_image): input_file = 'tests/data/models/liver.ply' model = VTKSurfaceModel(input_file, colors.red) model.set_texture('tests/data/images/image0232.png') image, widget, _, app = vtk_overlay_with_gradient_image widget.add_vtk_actor(model.actor) widget.show() # Save the scene to a file for parity check. # See test_set_texture_regression() below. # This line should be run again if the code is (purposefully) changed. #screenshot_filename = 'tests/data/images/set_texture_test.png' #widget.save_scene_to_file(screenshot_filename) #app.exec_() return model
def test_invalid_set_texture_because_texture_filename_empty(): input_file = 'tests/data/models/liver.ply' model = VTKSurfaceModel(input_file, colors.red) with pytest.raises(ValueError): model.set_texture('')
def test_invalid_set_texture_because_texture_file_format(): input_file = 'tests/data/models/liver.ply' model = VTKSurfaceModel(input_file, colors.red) texture_file = 'tox.ini' with pytest.raises(ValueError): model.set_texture(texture_file)