[9173ee]: / testing / mesh / meshes / Mesh_create_mesh_test.py

Download this file

105 lines (71 with data), 3.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
import numpy as np
import pytest
import SimpleITK as sitk
import pymskt as mskt
from pymskt.utils import testing
SEG_IMAGE_PATH = "data/right_knee_example.nrrd"
SEG_IMAGE = sitk.ReadImage(SEG_IMAGE_PATH)
MESH_NO_SMOOTHING = mskt.mesh.io.read_vtk("data/femur_orig_no_image_smoothing.vtk")
MESH_WITH_SMOOTHING = mskt.mesh.io.read_vtk("data/femur_mesh_orig.vtk")
from pymskt import ATOL, RTOL
# Testing create mesh no smoothing
def test_pass_seg_image_directly_no_smoothing_pass_label_idx_to_init(
seg_image=SEG_IMAGE, ref_mesh=MESH_NO_SMOOTHING, label_idx=5
):
mesh = mskt.mesh.Mesh(seg_image=seg_image, label_idx=label_idx)
mesh.create_mesh(smooth_image=False)
testing.assert_mesh_coordinates_same(ref_mesh, mesh.mesh, rtol=RTOL, atol=ATOL)
def test_pass_seg_image_directly_no_smoothing_pass_label_idx_to_create_mesh_function(
seg_image=SEG_IMAGE, ref_mesh=MESH_NO_SMOOTHING, label_idx=5
):
mesh = mskt.mesh.Mesh(seg_image=seg_image)
mesh.create_mesh(smooth_image=False, label_idx=label_idx)
testing.assert_mesh_coordinates_same(ref_mesh, mesh.mesh, rtol=RTOL, atol=ATOL)
# Testing create mesh with smoothing
def test_pass_seg_image_directly_with_smoothing_and_pass_label_idx_to_init(
seg_image=SEG_IMAGE, ref_mesh=MESH_WITH_SMOOTHING, label_idx=5, smooth_image_var=0.3125 / 2
):
mesh = mskt.mesh.Mesh(seg_image=seg_image, label_idx=label_idx)
mesh.create_mesh(smooth_image=True, smooth_image_var=smooth_image_var)
testing.assert_mesh_coordinates_same(ref_mesh, mesh.mesh, rtol=RTOL, atol=ATOL)
def test_pass_seg_image_directly_with_smoothing_and_pass_label_idx_to_create_mesh_function(
seg_image=SEG_IMAGE, ref_mesh=MESH_WITH_SMOOTHING, label_idx=5, smooth_image_var=0.3125 / 2
):
mesh = mskt.mesh.Mesh(seg_image=seg_image)
mesh.create_mesh(smooth_image=True, label_idx=label_idx, smooth_image_var=smooth_image_var)
testing.assert_mesh_coordinates_same(ref_mesh, mesh.mesh, rtol=RTOL, atol=ATOL)
def test_exception_n_pixels_less_than_min_n_pixels(seg_image=SEG_IMAGE, label_idx=5):
array = sitk.GetArrayFromImage(seg_image)
n_pixels = np.sum(array[array == label_idx])
with pytest.raises(Exception):
mesh = mskt.mesh.Mesh(seg_image=seg_image, label_idx=label_idx)
mesh.create_mesh(min_n_pixels=n_pixels + 1)
def test_exception_seg_image_provided_but_no_label_idx(
seg_image=SEG_IMAGE,
):
with pytest.raises(Exception):
mesh = mskt.mesh.Mesh(seg_image=seg_image)
mesh.create_mesh()
def test_exception_no_seg_image_or_path_to_seg_image_provided_and_smooth_image_true():
with pytest.raises(Exception):
mesh = mskt.mesh.Mesh(smooth_image=True)
mesh.create_mesh()
def test_exception_no_seg_image_or_path_to_seg_image_provided_and_smooth_image_false():
with pytest.raises(Exception):
mesh = mskt.mesh.Mesh(smooth_image=False)
mesh.create_mesh()
def test_load_seg_image_if_not_already_loaded(
path_seg_image=SEG_IMAGE_PATH, ref_mesh=MESH_NO_SMOOTHING, label_idx=5
):
mesh = mskt.mesh.Mesh(path_seg_image=path_seg_image, label_idx=label_idx)
mesh.create_mesh(smooth_image=False)
testing.assert_mesh_coordinates_same(ref_mesh, mesh.mesh, rtol=RTOL, atol=ATOL)
@pytest.mark.skip(reason="Test not implemented yet")
def test_specify_label_idx():
pass # TODO: Implement this test
@pytest.mark.skip(reason="Test not implemented yet")
def test_marching_cubes_threshold_0():
pass # TODO: Implement this test
@pytest.mark.skip(reason="Test not implemented yet")
def test_marching_cubes_threshold_1():
pass # TODO: Implement this test