示例#1
0
def to_geometry(geometry_like):
    if isinstance(geometry_like, itk.Mesh):
        if not hasattr(itk, 'PyVectorContainer'):
            raise ModuleNotFoundError(
                'itk.MeshToPolyDataFilter is not available -- install the itk-meshtopolydata package'
            )
        itk_polydata = itk.mesh_to_poly_data_filter(geometry_like)

        geometry = {'vtkClass': 'vtkPolyData'}

        points = itk_polydata.GetPoints()
        point_template = itk.template(points)
        element_type = point_template[1][1]
        # todo: test array_view here and below
        point_values = itk.PyVectorContainer[
            element_type].array_from_vector_container(points)
        if len(point_values.shape) > 1 and point_values.shape[
                1] == 2 or point_values.shape[1] == 3:
            if point_values.shape[1] == 2:
                point_values.resize((point_values.shape[0], 3))
                point_values[:, 2] = 0.0
            points = {
                'vtkClass': 'vtkPoints',
                'numberOfComponents': 3,
                'dataType': 'Float32Array',
                'size': point_values.size,
                'values': point_values
            }
            geometry['points'] = points
        else:
            return None

        itk_verts = itk_polydata.GetVertices()
        itk_lines = itk_polydata.GetLines()
        itk_polys = itk_polydata.GetPolygons()
        itk_strips = itk_polydata.GetTriangleStrips()
        for cell_type, itk_cells in [('verts', itk_verts),
                                     ('lines', itk_lines),
                                     ('polys', itk_polys),
                                     ('strips', itk_strips)]:
            if itk_cells.Size():
                data = itk.PyVectorContainer[
                    itk.UI].array_from_vector_container(itk_cells)
                cells = {
                    'vtkClass': 'vtkCellArray',
                    'name': '_' + cell_type,
                    'numberOfComponents': 1,
                    'size': data.size,
                    'dataType': 'Uint32Array',
                    'values': data
                }
                geometry[cell_type] = cells

        return geometry
    elif have_vtk and isinstance(geometry_like, vtk.vtkPolyData):
        from vtk.util.numpy_support import vtk_to_numpy

        geometry = {'vtkClass': 'vtkPolyData'}

        point_data = vtk_to_numpy(geometry_like.GetPoints().GetData())
        point_data = point_data.astype(np.float32).ravel()
        points = {
            'vtkClass': 'vtkPoints',
            'name': '_points',
            'numberOfComponents': 3,
            'dataType': 'Float32Array',
            'size': point_data.size,
            'values': point_data
        }
        geometry['points'] = points

        vtk_verts = geometry_like.GetVerts()
        vtk_lines = geometry_like.GetLines()
        vtk_polys = geometry_like.GetPolys()
        vtk_strips = geometry_like.GetStrips()
        for cell_type, vtk_cells in [('verts', vtk_verts),
                                     ('lines', vtk_lines),
                                     ('polys', vtk_polys),
                                     ('strips', vtk_strips)]:
            if vtk_cells.GetNumberOfCells():
                data = vtk_to_numpy(vtk_cells.GetData())
                data = data.astype(np.uint32).ravel()
                cells = {
                    'vtkClass': 'vtkCellArray',
                    'name': '_' + cell_type,
                    'numberOfComponents': 1,
                    'size': data.size,
                    'dataType': 'Uint32Array',
                    'values': data
                }
                geometry[cell_type] = cells

        return geometry

    return None
示例#2
0
def to_geometry(geometry_like):  # noqa: C901
    if isinstance(geometry_like, itk.Mesh):
        if not hasattr(itk, 'PyVectorContainer'):
            raise ImportError(
                'itk.MeshToPolyDataFilter is not available -- install the itk-meshtopolydata package'
            )
        itk_polydata = itk.mesh_to_poly_data_filter(geometry_like)

        geometry = {'vtkClass': 'vtkPolyData'}

        points = itk_polydata.GetPoints()
        point_template = itk.template(points)
        element_type = point_template[1][1]
        # todo: test array_view here and below
        point_values = itk.PyVectorContainer[
            element_type].array_from_vector_container(points)
        if len(point_values.shape) > 1 and point_values.shape[
                1] == 2 or point_values.shape[1] == 3:
            if point_values.shape[1] == 2:
                point_values.resize((point_values.shape[0], 3))
                point_values[:, 2] = 0.0
            points = {
                'vtkClass': 'vtkPoints',
                'numberOfComponents': 3,
                'dataType': 'Float32Array',
                'size': point_values.size,
                'values': point_values
            }
            geometry['points'] = points
        else:
            return None

        itk_verts = itk_polydata.GetVertices()
        itk_lines = itk_polydata.GetLines()
        itk_polys = itk_polydata.GetPolygons()
        itk_strips = itk_polydata.GetTriangleStrips()
        for cell_type, itk_cells in [('verts', itk_verts),
                                     ('lines', itk_lines),
                                     ('polys', itk_polys),
                                     ('strips', itk_strips)]:
            if itk_cells.Size():
                data = itk.PyVectorContainer[
                    itk.UI].array_from_vector_container(itk_cells)
                cells = {
                    'vtkClass': 'vtkCellArray',
                    'name': '_' + cell_type,
                    'numberOfComponents': 1,
                    'size': data.size,
                    'dataType': 'Uint32Array',
                    'values': data
                }
                geometry[cell_type] = cells

        itk_point_data = itk_polydata.GetPointData()
        if itk_point_data and itk_point_data.Size():
            pixel_type = itk.template(itk_polydata)[1][0]
            data_type, number_of_components = _itk_pixel_to_vtkjs_type_components[
                pixel_type]
            data = itk.PyVectorContainer[
                pixel_type].array_from_vector_container(itk_point_data)
            point_data = {
                "vtkClass":
                "vtkDataSetAttributes",
                "activeScalars":
                0,
                "arrays": [{
                    "data": {
                        'vtkClass': 'vtkDataArray',
                        'name': 'Point Data',
                        'numberOfComponents': number_of_components,
                        'size': data.size,
                        'dataType': data_type,
                        'values': data
                    }
                }],
            }
            geometry['pointData'] = point_data
        itk_cell_data = itk_polydata.GetCellData()
        if itk_cell_data and itk_cell_data.Size():
            pixel_type = itk.template(itk_polydata)[1][0]
            data_type, number_of_components = _itk_pixel_to_vtkjs_type_components[
                pixel_type]
            data = itk.PyVectorContainer[
                pixel_type].array_from_vector_container(itk_cell_data)
            cell_data = {
                "vtkClass":
                "vtkDataSetAttributes",
                "activeScalars":
                0,
                "arrays": [{
                    "data": {
                        'vtkClass': 'vtkDataArray',
                        'name': 'Cell Data',
                        'numberOfComponents': number_of_components,
                        'size': data.size,
                        'dataType': data_type,
                        'values': data
                    }
                }],
            }
            geometry['cellData'] = cell_data

        return geometry
    elif isinstance(geometry_like, itk.PolyLineParametricPath):
        vertex_list = geometry_like.GetVertexList()
        number_of_points = vertex_list.Size()
        geometry = {'vtkClass': 'vtkPolyData'}

        points_data = -5.0e-6 * \
            np.ones((number_of_points, 3), dtype=np.float64)
        dimension = len(vertex_list.GetElement(0))
        # Todo: replace with itk.PyVectorContainer direct NumPy conversion
        for index in range(number_of_points):
            points_data[index, :dimension] = vertex_list.GetElement(index)
        points_data = points_data.astype(np.float32).ravel()
        points = {
            'vtkClass': 'vtkPoints',
            'name': '_points',
            'numberOfComponents': 3,
            'dataType': 'Float32Array',
            'size': points_data.size,
            'values': points_data
        }
        geometry['points'] = points

        verts_data = np.ones((2 * number_of_points, ), dtype=np.uint32)
        verts_data[1::2] = np.arange(number_of_points, dtype=np.uint32)

        lines_data = 2 * \
            np.ones((3 * (number_of_points - 1),), dtype=np.uint32)
        lines_data[1::3] = np.arange(number_of_points - 1, dtype=np.uint32)
        lines_data[2::3] = np.arange(1, number_of_points, dtype=np.uint32)

        # For cell_type, cell_data in [('verts', verts_data),]:
        for cell_type, cell_data in [('verts', verts_data),
                                     ('lines', lines_data)]:
            cells = {
                'vtkClass': 'vtkCellArray',
                'name': '_' + cell_type,
                'numberOfComponents': 1,
                'size': cell_data.size,
                'dataType': 'Uint32Array',
                'values': cell_data
            }
            geometry[cell_type] = cells

        return geometry
    elif have_skan and isinstance(geometry_like, skan.csr.Skeleton):

        geometry = {'vtkClass': 'vtkPolyData'}

        number_of_points = geometry_like.coordinates.shape[0]
        dimension = geometry_like.coordinates.shape[1]

        points_data = -5.0e-6 * \
            np.ones((number_of_points, 3), dtype=np.float64)
        points_data[:, :dimension] = np.flip(
            geometry_like.coordinates[:, :dimension], 1)
        points_data = points_data.astype(np.float32).ravel()
        points = {
            'vtkClass': 'vtkPoints',
            'name': '_points',
            'numberOfComponents': 3,
            'dataType': 'Float32Array',
            'size': points_data.size,
            'values': points_data
        }
        geometry['points'] = points

        verts_data = np.empty((0, ), dtype=np.uint32)
        lines_data = np.empty((0, ), dtype=np.uint32)
        for path in geometry_like.paths_list():
            path_number_of_points = len(path)
            verts = np.ones((2 * path_number_of_points, ), dtype=np.uint32)
            verts[1::2] = np.array(path, dtype=np.uint32)
            verts_data = np.concatenate((verts_data, verts))

            lines = 2 * \
                np.ones((3 * (path_number_of_points - 1),), dtype=np.uint32)
            lines[1::3] = np.array(path[:-1], dtype=np.uint32)
            lines[2::3] = np.array(path[1:], dtype=np.uint32)
            lines_data = np.concatenate((lines_data, lines))

        for cell_type, cell_data in [('verts', verts_data),
                                     ('lines', lines_data)]:
            cells = {
                'vtkClass': 'vtkCellArray',
                'name': '_' + cell_type,
                'numberOfComponents': 1,
                'size': cell_data.size,
                'dataType': 'Uint32Array',
                'values': cell_data
            }
            geometry[cell_type] = cells

        return geometry
    elif have_vtk and isinstance(geometry_like, vtk.vtkPolyData):
        from vtk.util.numpy_support import vtk_to_numpy

        geometry = {'vtkClass': 'vtkPolyData'}

        points_data = vtk_to_numpy(geometry_like.GetPoints().GetData())
        points_data = points_data.astype(np.float32).ravel()
        points = {
            'vtkClass': 'vtkPoints',
            'name': '_points',
            'numberOfComponents': 3,
            'dataType': 'Float32Array',
            'size': points_data.size,
            'values': points_data
        }
        geometry['points'] = points

        vtk_verts = geometry_like.GetVerts()
        vtk_lines = geometry_like.GetLines()
        vtk_polys = geometry_like.GetPolys()
        vtk_strips = geometry_like.GetStrips()
        for cell_type, vtk_cells in [('verts', vtk_verts),
                                     ('lines', vtk_lines),
                                     ('polys', vtk_polys),
                                     ('strips', vtk_strips)]:
            if vtk_cells.GetNumberOfCells():
                data = vtk_to_numpy(vtk_cells.GetData())
                data = data.astype(np.uint32).ravel()
                cells = {
                    'vtkClass': 'vtkCellArray',
                    'name': '_' + cell_type,
                    'numberOfComponents': 1,
                    'size': data.size,
                    'dataType': 'Uint32Array',
                    'values': data
                }
                geometry[cell_type] = cells
        vtk_point_data = geometry_like.GetPointData()
        if vtk_point_data and vtk_point_data.GetNumberOfArrays():
            vtkjs_point_data = _vtk_data_attributes_to_vtkjs(vtk_point_data)
            geometry['pointData'] = vtkjs_point_data

        vtk_cell_data = geometry_like.GetCellData()
        if vtk_cell_data and vtk_cell_data.GetNumberOfArrays():
            vtkjs_cell_data = _vtk_data_attributes_to_vtkjs(vtk_cell_data)
            geometry['cellData'] = vtkjs_cell_data

        return geometry
    elif have_vtk and isinstance(
            geometry_like, (vtk.vtkUnstructuredGrid, vtk.vtkStructuredGrid,
                            vtk.vtkRectilinearGrid, vtk.vtkImageData)):
        geometry_filter = vtk.vtkGeometryFilter()
        geometry_filter.SetInputData(geometry_like)
        geometry_filter.Update()
        geometry = to_geometry(geometry_filter.GetOutput())
        return geometry
    elif isinstance(geometry_like, zarr.Group):
        return zarr_to_vtkjs(geometry_like)

    return None
示例#3
0
def to_geometry(geometry_like):
    if isinstance(geometry_like, itk.Mesh):
        if not hasattr(itk, 'PyVectorContainer'):
            raise ModuleNotFoundError(
                'itk.MeshToPolyDataFilter is not available -- install the itk-meshtopolydata package'
            )
        itk_polydata = itk.mesh_to_poly_data_filter(geometry_like)

        geometry = {'vtkClass': 'vtkPolyData'}

        points = itk_polydata.GetPoints()
        point_template = itk.template(points)
        element_type = point_template[1][1]
        # todo: test array_view here and below
        point_values = itk.PyVectorContainer[
            element_type].array_from_vector_container(points)
        if len(point_values.shape) > 1 and point_values.shape[
                1] == 2 or point_values.shape[1] == 3:
            if point_values.shape[1] == 2:
                point_values.resize((point_values.shape[0], 3))
                point_values[:, 2] = 0.0
            points = {
                'vtkClass': 'vtkPoints',
                'numberOfComponents': 3,
                'dataType': 'Float32Array',
                'size': point_values.size,
                'values': point_values
            }
            geometry['points'] = points
        else:
            return None

        itk_verts = itk_polydata.GetVertices()
        itk_lines = itk_polydata.GetLines()
        itk_polys = itk_polydata.GetPolygons()
        itk_strips = itk_polydata.GetTriangleStrips()
        for cell_type, itk_cells in [('verts', itk_verts),
                                     ('lines', itk_lines),
                                     ('polys', itk_polys),
                                     ('strips', itk_strips)]:
            if itk_cells.Size():
                data = itk.PyVectorContainer[
                    itk.UI].array_from_vector_container(itk_cells)
                cells = {
                    'vtkClass': 'vtkCellArray',
                    'name': '_' + cell_type,
                    'numberOfComponents': 1,
                    'size': data.size,
                    'dataType': 'Uint32Array',
                    'values': data
                }
                geometry[cell_type] = cells

        itk_point_data = itk_polydata.GetPointData()
        if itk_point_data and itk_point_data.Size():
            pixel_type = itk.template(itk_polydata)[1][0]
            data_type, number_of_components = _itk_pixel_to_vtkjs_type_components[
                pixel_type]
            data = itk.PyVectorContainer[
                pixel_type].array_from_vector_container(itk_point_data)
            point_data = {
                "vtkClass":
                "vtkDataSetAttributes",
                "activeScalars":
                0,
                "arrays": [{
                    "data": {
                        'vtkClass': 'vtkDataArray',
                        'name': 'Point Data',
                        'numberOfComponents': number_of_components,
                        'size': data.size,
                        'dataType': data_type,
                        'values': data
                    }
                }],
            }
            geometry['pointData'] = point_data
        itk_cell_data = itk_polydata.GetCellData()
        if itk_cell_data and itk_cell_data.Size():
            pixel_type = itk.template(itk_polydata)[1][0]
            data_type, number_of_components = _itk_pixel_to_vtkjs_type_components[
                pixel_type]
            data = itk.PyVectorContainer[
                pixel_type].array_from_vector_container(itk_cell_data)
            cell_data = {
                "vtkClass":
                "vtkDataSetAttributes",
                "activeScalars":
                0,
                "arrays": [{
                    "data": {
                        'vtkClass': 'vtkDataArray',
                        'name': 'Cell Data',
                        'numberOfComponents': number_of_components,
                        'size': data.size,
                        'dataType': data_type,
                        'values': data
                    }
                }],
            }
            geometry['cellData'] = cell_data

        return geometry
    elif have_vtk and isinstance(geometry_like, vtk.vtkPolyData):
        from vtk.util.numpy_support import vtk_to_numpy

        geometry = {'vtkClass': 'vtkPolyData'}

        points_data = vtk_to_numpy(geometry_like.GetPoints().GetData())
        points_data = points_data.astype(np.float32).ravel()
        points = {
            'vtkClass': 'vtkPoints',
            'name': '_points',
            'numberOfComponents': 3,
            'dataType': 'Float32Array',
            'size': points_data.size,
            'values': points_data
        }
        geometry['points'] = points

        vtk_verts = geometry_like.GetVerts()
        vtk_lines = geometry_like.GetLines()
        vtk_polys = geometry_like.GetPolys()
        vtk_strips = geometry_like.GetStrips()
        for cell_type, vtk_cells in [('verts', vtk_verts),
                                     ('lines', vtk_lines),
                                     ('polys', vtk_polys),
                                     ('strips', vtk_strips)]:
            if vtk_cells.GetNumberOfCells():
                data = vtk_to_numpy(vtk_cells.GetData())
                data = data.astype(np.uint32).ravel()
                cells = {
                    'vtkClass': 'vtkCellArray',
                    'name': '_' + cell_type,
                    'numberOfComponents': 1,
                    'size': data.size,
                    'dataType': 'Uint32Array',
                    'values': data
                }
                geometry[cell_type] = cells
        vtk_point_data = geometry_like.GetPointData()
        if vtk_point_data and vtk_point_data.GetNumberOfArrays():
            vtkjs_point_data = _vtk_data_attributes_to_vtkjs(vtk_point_data)
            geometry['pointData'] = vtkjs_point_data

        vtk_cell_data = geometry_like.GetCellData()
        if vtk_cell_data and vtk_cell_data.GetNumberOfArrays():
            vtkjs_cell_data = _vtk_data_attributes_to_vtkjs(vtk_cell_data)
            geometry['cellData'] = vtkjs_cell_data

        return geometry
    elif have_vtk and isinstance(
            geometry_like, (vtk.vtkUnstructuredGrid, vtk.vtkStructuredGrid,
                            vtk.vtkRectilinearGrid, vtk.vtkImageData)):
        geometry_filter = vtk.vtkGeometryFilter()
        geometry_filter.SetInputData(geometry_like)
        geometry_filter.Update()
        geometry = to_geometry(geometry_filter.GetOutput())
        return geometry

    return None
示例#4
0
def to_point_set(point_set_like):  # noqa: C901
    if isinstance(point_set_like, itk.PointSet):
        if not hasattr(itk, 'PyVectorContainer'):
            raise ImportError(
                'itk.MeshToPolyDataFilter is not available -- install the itk-meshtopolydata package'
            )
        itk_polydata = itk.mesh_to_poly_data_filter(point_set_like)

        point_set = {'vtkClass': 'vtkPolyData'}

        points = itk_polydata.GetPoints()
        point_template = itk.template(points)
        element_type = point_template[1][1]
        # todo: test array_view here and below
        point_values = itk.PyVectorContainer[
            element_type].array_from_vector_container(points)
        if len(point_values.shape) > 1 and point_values.shape[
                1] == 2 or point_values.shape[1] == 3:
            if point_values.shape[1] == 2:
                point_values = np.hstack((point_values, -5.0e-6 * np.ones(
                    (point_values.shape[0], 1)))).astype(np.float32)
            points = {
                'vtkClass': 'vtkPoints',
                'numberOfComponents': 3,
                'dataType': 'Float32Array',
                'size': point_values.size,
                'values': point_values
            }
            point_set['points'] = points
        else:
            return None

        itk_point_data = itk_polydata.GetPointData()
        if itk_point_data and itk_point_data.Size():
            pixel_type = itk.template(itk_polydata)[1][0]
            data_type, number_of_components = _itk_pixel_to_vtkjs_type_components[
                pixel_type]
            data = itk.PyVectorContainer[
                pixel_type].array_from_vector_container(itk_point_data)
            point_data = {
                "vtkClass":
                "vtkDataSetAttributes",
                "activeScalars":
                0,
                "arrays": [{
                    "data": {
                        'vtkClass': 'vtkDataArray',
                        'name': 'Point Data',
                        'numberOfComponents': number_of_components,
                        'size': data.size,
                        'dataType': data_type,
                        'values': data
                    }
                }],
            }
            point_set['pointData'] = point_data

        return point_set
    elif isinstance(point_set_like, itk.GroupSpatialObject):
        children = point_set_like.GetChildren()

        point_set = {'vtkClass': 'vtkPolyData'}

        points_list = []
        for ii in range(len(children)):
            child = children[ii]
            down_casted = itk.down_cast(child)
            if isinstance(down_casted, itk.PointBasedSpatialObject):
                n_points = down_casted.GetNumberOfPoints()
                for ii in range(n_points):
                    point = down_casted.GetPoint(ii)
                    point.SetSpatialObject(down_casted)
                    position = point.GetPositionInWorldSpace()
                    points_list.append(list(position))
        return _numpy_array_to_point_set(points_list)
    elif is_arraylike(point_set_like):
        return _numpy_array_to_point_set(point_set_like)
    elif have_vtk and isinstance(point_set_like, vtk.vtkPolyData):
        from vtk.util.numpy_support import vtk_to_numpy
        point_set = {'vtkClass': 'vtkPolyData'}

        points_data = vtk_to_numpy(point_set_like.GetPoints().GetData())
        points_data = points_data.astype(np.float32).ravel()
        points = {
            'vtkClass': 'vtkPoints',
            'name': '_points',
            'numberOfComponents': 3,
            'dataType': 'Float32Array',
            'size': points_data.size,
            'values': points_data
        }
        point_set['points'] = points

        vtk_verts = point_set_like.GetVerts()
        if vtk_verts.GetNumberOfCells():
            data = vtk_to_numpy(vtk_verts.GetData())
            data = data.astype(np.uint32).ravel()
            cells = {
                'vtkClass': 'vtkCellArray',
                'name': '_' + 'verts',
                'numberOfComponents': 1,
                'size': data.size,
                'dataType': 'Uint32Array',
                'values': data
            }
            point_set['verts'] = cells
        vtk_point_data = point_set_like.GetPointData()
        if vtk_point_data and vtk_point_data.GetNumberOfArrays():
            vtkjs_point_data = _vtk_data_attributes_to_vtkjs(vtk_point_data)
            point_set['pointData'] = vtkjs_point_data

        vtk_cell_data = point_set_like.GetCellData()
        if vtk_cell_data and vtk_cell_data.GetNumberOfArrays():
            vtkjs_cell_data = _vtk_data_attributes_to_vtkjs(vtk_cell_data)
            point_set['cellData'] = vtkjs_cell_data

        return point_set
    elif isinstance(point_set_like, zarr.Group):
        return zarr_to_vtkjs(point_set_like)

    return None
示例#5
0
def to_point_set(point_set_like):
    if isinstance(point_set_like, itk.PointSet):
        if not hasattr(itk, 'PyVectorContainer'):
            raise ModuleNotFoundError(
                'itk.MeshToPolyDataFilter is not available -- install the itk-meshtopolydata package'
            )
        itk_polydata = itk.mesh_to_poly_data_filter(point_set_like)

        point_set = {'vtkClass': 'vtkPolyData'}

        points = itk_polydata.GetPoints()
        point_template = itk.template(points)
        element_type = point_template[1][1]
        # todo: test array_view here and below
        point_values = itk.PyVectorContainer[
            element_type].array_from_vector_container(points)
        if len(point_values.shape) > 1 and point_values.shape[
                1] == 2 or point_values.shape[1] == 3:
            if point_values.shape[1] == 2:
                point_values.resize((point_values.shape[0], 3))
                point_values[:, 2] = 0.0
            points = {
                'vtkClass': 'vtkPoints',
                'numberOfComponents': 3,
                'dataType': 'Float32Array',
                'size': point_values.size,
                'values': point_values
            }
            point_set['points'] = points
        else:
            return None

        itk_point_data = itk_polydata.GetPointData()
        if itk_point_data and itk_point_data.Size():
            pixel_type = itk.template(itk_polydata)[1][0]
            data_type, number_of_components = _itk_pixel_to_vtkjs_type_components[
                pixel_type]
            data = itk.PyVectorContainer[
                pixel_type].array_from_vector_container(itk_point_data)
            point_data = {
                "vtkClass":
                "vtkDataSetAttributes",
                "activeScalars":
                0,
                "arrays": [{
                    "data": {
                        'vtkClass': 'vtkDataArray',
                        'name': 'Point Data',
                        'numberOfComponents': number_of_components,
                        'size': data.size,
                        'dataType': data_type,
                        'values': data
                    }
                }],
            }
            point_set['pointData'] = point_data

        return point_set
    elif is_arraylike(point_set_like):
        point_values = np.asarray(point_set_like).astype(np.float32)
        if len(point_values.shape) > 1 and point_values.shape[
                1] == 2 or point_values.shape[1] == 3:
            if point_values.shape[1] == 2:
                point_values.resize((point_values.shape[0], 3))
                point_values[:, 2] = 0.0
            point_set = {'vtkClass': 'vtkPolyData'}
            points = {
                'vtkClass': 'vtkPoints',
                'name': '_points',
                'numberOfComponents': 3,
                'dataType': 'Float32Array',
                'size': point_values.size,
                'values': point_values
            }
            point_set['points'] = points
            vert_values = np.ones((point_values.size * 2, ), dtype=np.uint32)
            vert_values[1::2] = np.arange(point_values.size)
            verts = {
                'vtkClass': 'vtkCellArray',
                'name': '_verts',
                'numberOfComponents': 1,
                'dataType': 'Uint32Array',
                'size': vert_values.size,
                'values': vert_values
            }
            point_set['verts'] = verts
            return point_set
        else:
            return None
    elif have_vtk and isinstance(point_set_like, vtk.vtkPolyData):
        from vtk.util.numpy_support import vtk_to_numpy
        point_set = {'vtkClass': 'vtkPolyData'}

        points_data = vtk_to_numpy(point_set_like.GetPoints().GetData())
        points_data = points_data.astype(np.float32).ravel()
        points = {
            'vtkClass': 'vtkPoints',
            'name': '_points',
            'numberOfComponents': 3,
            'dataType': 'Float32Array',
            'size': points_data.size,
            'values': points_data
        }
        point_set['points'] = points

        vtk_verts = point_set_like.GetVerts()
        if vtk_verts.GetNumberOfCells():
            data = vtk_to_numpy(vtk_verts.GetData())
            data = data.astype(np.uint32).ravel()
            cells = {
                'vtkClass': 'vtkCellArray',
                'name': '_' + 'verts',
                'numberOfComponents': 1,
                'size': data.size,
                'dataType': 'Uint32Array',
                'values': data
            }
            point_set['verts'] = cells
        vtk_point_data = point_set_like.GetPointData()
        if vtk_point_data and vtk_point_data.GetNumberOfArrays():
            vtkjs_point_data = _vtk_data_attributes_to_vtkjs(vtk_point_data)
            point_set['pointData'] = vtkjs_point_data

        vtk_cell_data = point_set_like.GetCellData()
        if vtk_cell_data and vtk_cell_data.GetNumberOfArrays():
            vtkjs_cell_data = _vtk_data_attributes_to_vtkjs(vtk_cell_data)
            point_set['cellData'] = vtkjs_cell_data

        return point_set

    return None