def tractography_from_vtk_files(vtk_file_names):
    tr = Tractography()

    if isinstance(vtk_file_names, str):
        vtk_file_names = [vtk_file_names]

    for file_name in vtk_file_names:
        tracts = read_vtkPolyData(file_name)
        tr.append(tracts.tracts(), tracts.tracts_data())

    return tr
Exemplo n.º 2
0
def tractography_from_vtk_files(vtk_file_names):
    tr = Tractography()

    if isinstance(vtk_file_names, str):
        vtk_file_names = [vtk_file_names]

    for file_name in vtk_file_names:
        tracts = read_vtkPolyData(file_name)
        tr.append(tracts.tracts(), tracts.tracts_data())

    return tr
def vtkPolyData_to_tracts(polydata, return_tractography_object=True):
    r'''
    Reads a VTKPolyData object and outputs a tracts/tracts_data pair

    Parameters
    ----------
    polydata : vtkPolyData
        VTKPolyData Object

    Returns
    -------
    tracts : list of float array N_ix3
        Each element of the list is a tract represented as point array,
        the length of the i-th tract is N_i
    tract_data : dict of <data name>= list of float array of N_ixM
        Each element in the list corresponds to a tract,
        N_i is the length of the i-th tract and M is the
        number of components of that data type.
    '''

    result = {}
    result['lines'] = ns.vtk_to_numpy(polydata.GetLines().GetData())
    result['points'] = ns.vtk_to_numpy(polydata.GetPoints().GetData())
    result['numberOfLines'] = polydata.GetNumberOfLines()

    data = {}
    if polydata.GetPointData().GetScalars():
        data['ActiveScalars'] = polydata.GetPointData().GetScalars().GetName()
    if polydata.GetPointData().GetVectors():
        data['ActiveVectors'] = polydata.GetPointData().GetVectors().GetName()
    if polydata.GetPointData().GetTensors():
        data['ActiveTensors'] = polydata.GetPointData().GetTensors().GetName()

    for i in xrange(polydata.GetPointData().GetNumberOfArrays()):
        array = polydata.GetPointData().GetArray(i)
        np_array = ns.vtk_to_numpy(array)
        if np_array.ndim == 1:
            np_array = np_array.reshape(len(np_array), 1)
        data[polydata.GetPointData().GetArrayName(i)] = np_array

    result['pointData'] = data

    tracts, data = vtkPolyData_dictionary_to_tracts_and_data(result)
    if return_tractography_object:
        tr = Tractography()
        tr.append(tracts, data)
        return tr
    else:
        return tracts, data
Exemplo n.º 4
0
def vtkPolyData_to_tracts(polydata, return_tractography_object=True):
    r'''
    Reads a VTKPolyData object and outputs a tracts/tracts_data pair

    Parameters
    ----------
    polydata : vtkPolyData
        VTKPolyData Object

    Returns
    -------
    tracts : list of float array N_ix3
        Each element of the list is a tract represented as point array,
        the length of the i-th tract is N_i
    tract_data : dict of <data name>= list of float array of N_ixM
        Each element in the list corresponds to a tract,
        N_i is the length of the i-th tract and M is the
        number of components of that data type.
    '''

    result = {}
    result['lines'] = ns.vtk_to_numpy(polydata.GetLines().GetData())
    result['points'] = ns.vtk_to_numpy(polydata.GetPoints().GetData())
    result['numberOfLines'] = polydata.GetNumberOfLines()

    data = {}
    if polydata.GetPointData().GetScalars():
        data['ActiveScalars'] = polydata.GetPointData().GetScalars().GetName()
    if polydata.GetPointData().GetVectors():
        data['ActiveVectors'] = polydata.GetPointData().GetVectors().GetName()
    if polydata.GetPointData().GetTensors():
        data['ActiveTensors'] = polydata.GetPointData().GetTensors().GetName()

    for i in xrange(polydata.GetPointData().GetNumberOfArrays()):
        array = polydata.GetPointData().GetArray(i)
        np_array = ns.vtk_to_numpy(array)
        if np_array.ndim == 1:
            np_array = np_array.reshape(len(np_array), 1)
        data[polydata.GetPointData().GetArrayName(i)] = np_array

    result['pointData'] = data

    tracts, data = vtkPolyData_dictionary_to_tracts_and_data(result)
    if return_tractography_object:
        tr = Tractography()
        tr.append(tracts, data)
        return tr
    else:
        return tracts, data