MCPcopy
hub / github.com/mne-tools/mne-python / _read_wavefront_obj

Function _read_wavefront_obj

mne/surface.py:1043–1075  ·  view source on GitHub ↗

Read a surface form a Wavefront .obj file. Parameters ---------- fname : str Name of the .obj file to read. Returns ------- coords : ndarray, shape (n_points, 3) The XYZ coordinates of each vertex. faces : ndarray, shape (n_faces, 3) For each fac

(fname)

Source from the content-addressed store, hash-verified

1041
1042
1043def _read_wavefront_obj(fname):
1044 """Read a surface form a Wavefront .obj file.
1045
1046 Parameters
1047 ----------
1048 fname : str
1049 Name of the .obj file to read.
1050
1051 Returns
1052 -------
1053 coords : ndarray, shape (n_points, 3)
1054 The XYZ coordinates of each vertex.
1055 faces : ndarray, shape (n_faces, 3)
1056 For each face of the mesh, the integer indices of the vertices that
1057 make up the face.
1058 """
1059 coords = []
1060 faces = []
1061 with open(fname) as f:
1062 for line in f:
1063 line = line.strip()
1064 if len(line) == 0 or line[0] == "#":
1065 continue
1066 split = line.split()
1067 if split[0] == "v": # vertex
1068 coords.append([float(item) for item in split[1:]])
1069 elif split[0] == "f": # face
1070 dat = [int(item.split("/")[0]) for item in split[1:]]
1071 if len(dat) != 3:
1072 raise RuntimeError("Only triangle faces allowed.")
1073 # In .obj files, indexing starts at 1
1074 faces.append([d - 1 for d in dat])
1075 return np.array(coords), np.array(faces)
1076
1077
1078def _read_patch(fname):

Callers 1

read_surfaceFunction · 0.85

Calls 2

splitMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected