Skip to content

read

read_ply(path)

Reader for '.ply' files.

Parameters:

Name Type Description Default
path str | Path

Disc location of the file to read.

required

Returns:

Type Description
simplices

list of lists of vertex ids surrounding each cell.

positions

A Nx3 array of floats. Where N = number of vertices.

Notes
  • In the .ply format we tend to save only SimplicialComplex objects.
  • Cochain objects must be saved in .vtk format.
  • TODO: Should also check elements of lower order to see if they contain simplices to extract. So far only pure simplicial complexes are handled.
  • TODO: Should also check and extract other properties in order to read Cochains.
Source code in src/dxtr/io/read.py
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
def read_ply(path:str|Path) -> tuple[Optional[list[list[int]]],
                                        Optional[np.ndarray[float]]]:
    """Reader for '.ply' files.

    Parameters
    ----------
    path
        Disc location of the file to read.

    Returns
    -------
    simplices
        list of lists of vertex ids surrounding each cell.
    positions
        A Nx3 array of floats. Where N = number of vertices.

    Notes
    -----
      * In the `.ply` format we tend to save only `SimplicialComplex` objects.
      * `Cochain` objects must be saved in `.vtk` format.
      * TODO: Should also check elements of lower order to see if they contain 
        simplices to extract. So far only pure simplicial complexes are handled.
      * TODO: Should also check and extract other properties 
        in order to read Cochains.
    """

    if not _valid(path): return None, None

    with open(path, 'r') as file:
        content = file.readlines()
        elements = _parse_elements_and_properties(content)

        positions = elements[0].extract_positions()
        simplices = elements[-1].extract_simplices()

        if not elements[-1].is_simplex:
            positions = _cells_circumcenters(positions, content)

        return simplices, positions

read_vtk(path)

Reader for .vtk files of a pure SimplicialComplex or Cochain.

Parameters:

Name Type Description Default
path str | Path

The location of the file to read.

required

Returns:

Type Description
simplices

A (Nn, n+1) array containing the top vertex indices (n+1 indices per n-simplex) for each of the Nn top simplices (of topological dimension n).

positions

A (N0, 3) array containing the 3D position vectors of the N0 0-simplices.

property

A Property object containing the data useful for the Cochain instanciation.

Notes
  • Only works so far on Primal scalar-valued Cochain !!!
Source code in src/dxtr/io/read.py
 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
105
106
107
108
109
110
111
@require_pyvista
def read_vtk(path:str|Path) -> tuple[Optional[np.ndarray[int]],
                                     Optional[np.ndarray[float]]]:
    """Reader for `.vtk` files of a pure `SimplicialComplex` or `Cochain`.

    Parameters
    ----------
    path
        The location of the file to read.

    Returns
    -------
    simplices
        A (Nn, n+1) array containing the top vertex indices 
        (n+1 indices per n-simplex) for each of the Nn top simplices 
        (of topological dimension n).
    positions
        A (N0, 3) array containing the 3D position vectors of the 
        N0 0-simplices.
    property
        A `Property` object containing the data useful for the `Cochain`
        instanciation.

    Notes
    -----
      * Only works so far on Primal scalar-valued Cochain !!!
    """

    if not _valid(path): return None, None, None

    ugrid = pv.read(path, file_format='vtk')

    positions = ugrid.points
    simplices = _top_simplices_within(ugrid)
    property = _data_within(ugrid)

    return simplices, positions, property