How to use itkwidgets - 10 common examples

To help you get started, we’ve selected a few itkwidgets examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github InsightSoftwareConsortium / itkwidgets / tests / test_trait_types.py View on Github external
def test_polydata_list_from_json():
    number_of_points = 10
    point_set_array_1 = np.random.multivariate_normal(gaussian_1_mean, gaussian_1_cov,
                                                      number_of_points)
    point_set_array_2 = np.random.multivariate_normal(gaussian_2_mean, gaussian_2_cov,
                                                      number_of_points)

    point_set_1 = to_point_set(point_set_array_1)
    point_set_2 = to_point_set(point_set_array_2)
    polydata_list = [point_set_1, point_set_2]

    asjson = trait_types.polydata_list_to_json(polydata_list)
    polydata_list_from_json = trait_types.polydata_list_from_json(asjson)
    assert(len(polydata_list_from_json) == 2)
    polydata_1 = polydata_list_from_json[0]
    assert(polydata_1['vtkClass'] == 'vtkPolyData')
    assert(polydata_1['points']['vtkClass'] == 'vtkPoints')
    assert(polydata_1['points']['numberOfComponents'] == 3)
    assert(polydata_1['points']['dataType'] == 'Float32Array')
    assert(np.array_equal(polydata_1['points']['values'],
                          point_set_array_1.astype(np.float32)))
github InsightSoftwareConsortium / itkwidgets / tests / test_trait_types.py View on Github external
def test_polydata_list_to_json():
    number_of_points = 10
    point_set_array_1 = np.random.multivariate_normal(gaussian_1_mean, gaussian_1_cov,
                                                      number_of_points)
    point_set_array_2 = np.random.multivariate_normal(gaussian_2_mean, gaussian_2_cov,
                                                      number_of_points)

    point_set_1 = to_point_set(point_set_array_1)
    point_set_2 = to_point_set(point_set_array_2)
    polydata_list = [point_set_1, point_set_2]

    asjson = trait_types.polydata_list_to_json(polydata_list)
    assert(len(asjson) == 2)
    polydata_1 = asjson[0]
    assert(polydata_1['vtkClass'] == 'vtkPolyData')
    assert(polydata_1['points']['vtkClass'] == 'vtkPoints')
    assert(polydata_1['points']['numberOfComponents'] == 3)
    assert(polydata_1['points']['dataType'] == 'Float32Array')
    assert(len(polydata_1['points']['compressedValues']) == 129)
github InsightSoftwareConsortium / itkwidgets / tests / test_trait_types.py View on Github external
def test_polydata_list_from_json():
    number_of_points = 10
    point_set_array_1 = np.random.multivariate_normal(gaussian_1_mean, gaussian_1_cov,
                                                      number_of_points)
    point_set_array_2 = np.random.multivariate_normal(gaussian_2_mean, gaussian_2_cov,
                                                      number_of_points)

    point_set_1 = to_point_set(point_set_array_1)
    point_set_2 = to_point_set(point_set_array_2)
    polydata_list = [point_set_1, point_set_2]

    asjson = trait_types.polydata_list_to_json(polydata_list)
    polydata_list_from_json = trait_types.polydata_list_from_json(asjson)
    assert(len(polydata_list_from_json) == 2)
    polydata_1 = polydata_list_from_json[0]
    assert(polydata_1['vtkClass'] == 'vtkPolyData')
    assert(polydata_1['points']['vtkClass'] == 'vtkPoints')
    assert(polydata_1['points']['numberOfComponents'] == 3)
    assert(polydata_1['points']['dataType'] == 'Float32Array')
    assert(np.array_equal(polydata_1['points']['values'],
                          point_set_array_1.astype(np.float32)))
github InsightSoftwareConsortium / itkwidgets / tests / test_trait_types.py View on Github external
def test_polydata_list_to_json():
    number_of_points = 10
    point_set_array_1 = np.random.multivariate_normal(gaussian_1_mean, gaussian_1_cov,
                                                      number_of_points)
    point_set_array_2 = np.random.multivariate_normal(gaussian_2_mean, gaussian_2_cov,
                                                      number_of_points)

    point_set_1 = to_point_set(point_set_array_1)
    point_set_2 = to_point_set(point_set_array_2)
    polydata_list = [point_set_1, point_set_2]

    asjson = trait_types.polydata_list_to_json(polydata_list)
    assert(len(asjson) == 2)
    polydata_1 = asjson[0]
    assert(polydata_1['vtkClass'] == 'vtkPolyData')
    assert(polydata_1['points']['vtkClass'] == 'vtkPoints')
    assert(polydata_1['points']['numberOfComponents'] == 3)
    assert(polydata_1['points']['dataType'] == 'Float32Array')
    assert(len(polydata_1['points']['compressedValues']) == 129)
github InsightSoftwareConsortium / itkwidgets / tests / test_transform_types.py View on Github external
point_set_array = np.random.multivariate_normal(gaussian_1_mean, gaussian_1_cov,
                                                    number_of_points)

    # 3D
    point_set = to_point_set(point_set_array)
    assert(point_set['vtkClass'] == 'vtkPolyData')
    assert(point_set['points']['vtkClass'] == 'vtkPoints')
    assert(point_set['points']['numberOfComponents'] == 3)
    assert(point_set['points']['dataType'] == 'Float32Array')
    assert(point_set['points']['size'] == number_of_points * 3)
    assert(np.array_equal(point_set['points']['values'],
                          point_set_array.astype(np.float32)))

    # 2D
    point_set_array.resize((number_of_points, 2))
    point_set = to_point_set(point_set_array)
    assert(point_set['vtkClass'] == 'vtkPolyData')
    assert(point_set['points']['vtkClass'] == 'vtkPoints')
    assert(point_set['points']['numberOfComponents'] == 3)
    assert(point_set['points']['dataType'] == 'Float32Array')
    assert(point_set['points']['size'] == number_of_points * 3)

    point_set_array = np.hstack(
        (point_set_array, -5.0e-6 * np.ones((point_set_array.shape[0], 1)))).astype(np.float32)
    assert(np.alltrue(point_set['points']['values'] ==
                      point_set_array.astype(np.float32)))
github InsightSoftwareConsortium / itkwidgets / tests / test_transform_types.py View on Github external
def test_itkpolylineparametricpath_to_geometry():
    Dimension = 2
    polyline = itk.PolyLineParametricPath[Dimension].New()
    polyline.AddVertex([3.0, 3.0])
    polyline.AddVertex([4.0, 7.0])
    polyline.AddVertex([5.0, 5.0])

    geometry = to_geometry(polyline)

    assert(geometry['vtkClass'] == 'vtkPolyData')
    assert(geometry['points']['vtkClass'] == 'vtkPoints')
    assert(geometry['points']['numberOfComponents'] == 3)
    assert(geometry['points']['dataType'] == 'Float32Array')
    assert(geometry['points']['size'] == 3 * 3)
    assert(np.array_equal(geometry['points']['values'],
                          np.array([3.0, 3.0, -5.0e-6, 4.0, 7.0, -5e-6, 5.0, 5.0, -5e-6]).astype(np.float32)))

    assert(geometry['verts']['vtkClass'] == 'vtkCellArray')
    assert(geometry['verts']['numberOfComponents'] == 1)
    assert(geometry['verts']['dataType'] == 'Uint32Array')
    assert(geometry['verts']['size'] == 6)
    assert(np.array_equal(geometry['verts']['values'],
                          [1, 0, 1, 1, 1, 2]))
    assert(geometry['lines']['vtkClass'] == 'vtkCellArray')
github InsightSoftwareConsortium / itkwidgets / tests / test_transform_types.py View on Github external
mesh.SetPointData(1, 9.0)
    mesh.SetPoint(1, point1)
    point2 = PointType()
    point2[0] = 1
    point2[1] = 1
    point2[2] = 0
    mesh.SetPoint(2, point2)
    mesh.SetPointData(2, 19.0)
    point3 = PointType()
    point3[0] = 1
    point3[1] = 1
    point3[2] = 0
    mesh.SetPoint(3, point3)
    mesh.SetPointData(3, 24.0)

    geometry = to_geometry(mesh)

    points = mesh.GetPoints()
    point_template = itk.template(points)
    element_type = point_template[1][1]
    point_values = itk.PyVectorContainer[element_type].array_from_vector_container(
        points)

    assert(geometry['vtkClass'] == 'vtkPolyData')
    assert(geometry['points']['vtkClass'] == 'vtkPoints')
    assert(geometry['points']['numberOfComponents'] == 3)
    assert(geometry['points']['dataType'] == 'Float32Array')
    assert(geometry['points']['size'] == 4 * 3)
    assert(np.array_equal(geometry['points']['values'],
                          point_values.astype(np.float32)))
    assert(geometry['pointData']['vtkClass'] == 'vtkDataSetAttributes')
    assert(geometry['pointData']['arrays'][0]
github InsightSoftwareConsortium / itkwidgets / tests / test_transform_types.py View on Github external
cone_source = vtk.vtkConeSource()
    cone_source.Update()
    cone = cone_source.GetOutput()

    points = cone.GetPoints()
    point_scalars = vtk.vtkFloatArray()
    for ii in range(points.GetNumberOfPoints()):
        point_scalars.InsertTuple1(ii, ii)
    cone.GetPointData().SetScalars(point_scalars)

    cell_scalars = vtk.vtkFloatArray()
    for ii in range(cone.GetNumberOfCells()):
        cell_scalars.InsertTuple1(ii, ii)
    cone.GetCellData().SetScalars(cell_scalars)

    geometry = to_geometry(cone)

    assert(geometry['vtkClass'] == 'vtkPolyData')

    assert(geometry['points']['vtkClass'] == 'vtkPoints')
    assert(geometry['points']['numberOfComponents'] == 3)
    assert(geometry['points']['dataType'] == 'Float32Array')
    assert(geometry['points']['size'] == points.GetNumberOfPoints() * 3)
    assert(np.array_equal(geometry['points']['values'],
                          vtk_to_numpy(points.GetData()).astype(np.float32).ravel()))

    polys = cone.GetPolys()
    assert(geometry['polys']['vtkClass'] == 'vtkCellArray')
    assert(geometry['polys']['numberOfComponents'] == 1)
    assert(geometry['polys']['dataType'] == 'Uint32Array')
    assert(geometry['polys']['size'] == polys.GetData().GetNumberOfValues())
    assert(np.array_equal(geometry['polys']['values'],
github InsightSoftwareConsortium / itkwidgets / tests / test_transform_types.py View on Github external
def test_non_contiguous_array():
    "Check that a non-contiguous array raises the appropriate error"

    data = np.random.random((10, 10, 10))
    data = data[..., 0]   # slicing the array makes it non-contiguous
    output = to_itk_image(data)
    assert isinstance(output, itk.Image)
github InsightSoftwareConsortium / itkwidgets / tests / test_trait_types.py View on Github external
def test_ITKImage():
    info_text = trait_types.ITKImage.info_text
    assert(info_text.find('image') != -1)